Registering two same name contracts #331
|
this is the example from the docs [ImportGrpcService(typeof(IMyContract1))]
[ImportGrpcService(typeof(IMyContract2))]
internal static partial class MyGrpcServices
{
// generated code ...
public static IClientFactory AddMyContract1Client(this IClientFactory clientFactory, Action<ServiceModelGrpcClientOptions> configure = null) {}
// generated code ...
public static IClientFactory AddMyContract2Client(this IClientFactory clientFactory, Action<ServiceModelGrpcClientOptions> configure = null) {}
}My situation is that the two contracts have the same name but in different namespace. When I add ImportedGrpcService attributes to both of the contracts, the generated 'Add~' method gives this error 'The call is ambiguous between the following methods or properties:' Does the contracts have to have different names? How can I solve this error without changing the name of my contracts? |
Answered by
max-ieremenko
Feb 22, 2025
Replies: 1 comment
|
For whatever reason two contracts have the same name but in different namespaces namespace Standard
{
[ServiceContract]
public interface ICalculator { }
}
namespace Scientific
{
[ServiceContract]
public interface ICalculator { }
}The client, option 1 namespace Client;
[ImportGrpcService(typeof(Standard.ICalculator))]
public static partial class StandardClients
{
// generated code
static AddCalculatorClient(this IClientFactory clientFactory)
}
[ImportGrpcService(typeof(Scientific.ICalculator))]
public static partial class ScientificClients
{
// generated code
static AddCalculatorClient(this IClientFactory clientFactory)
}
IClientFactory clientFactory = ...
// the compiler complains about CS0121 The call is ambiguous between the following methods or properties
// StandardClients.AddCalculatorClient or ScientificClients.AddCalculatorClient
clientFactory.AddCalculatorClient();
// be precise
StandardClients.AddCalculatorClient(clientFactory, options => {});
ScientificClients.AddCalculatorClient(clientFactory, options => {});The client, option 2, follows your naming convention namespace Standard
{
[ImportGrpcService(typeof(ICalculator))]
public static partial class MyGrpcClients
{
// generated code
static AddCalculatorClient(this IClientFactory clientFactory)
// your code
static void AddMyStandardClients(this IClientFactory clientFactory)
{
clientFactory.AddCalculatorClient();
}
}
}
namespace Scientific
{
[ImportGrpcService(typeof(ICalculator))]
public static partial class MyGrpcClients
{
// generated code
static AddCalculatorClient(this IClientFactory clientFactory)
// your code
static void AddMyScientificClients(this IClientFactory clientFactory)
{
clientFactory.AddCalculatorClient();
}
}
}
IClientFactory clientFactory = ...
clientFactory.AddMyStandardClients(options => {});
clientFactory.AddMyScientificClients(options => {}); |
0 replies
Answer selected by
EunjeongChoi414
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For whatever reason two contracts have the same name but in different namespaces
The client, option 1