Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared interface (contract) #70

Closed
max-ieremenko opened this issue Jan 29, 2022 · 1 comment
Closed

Shared interface (contract) #70

max-ieremenko opened this issue Jan 29, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@max-ieremenko
Copy link
Owner

Problem

[ServiceContract]
public interface IService
{
    // method: POST /IService/SomeOperation
    [OperationContract]
    Task SomeOperation();
}

[ServiceContract]
public interface IConcreteService1 : IService { /* skip other operations ... */ }

[ServiceContract]
public interface IConcreteService2 : IService { /* skip other operations ... */ }

class ConcreteService1 : IConcreteService1
{
    public Task SomeOperation() { /* do something in the context of ConcreteService1 */ }
}

class ConcreteService2 : IConcreteService2
{
    public Task SomeOperation() { /* do something else in the context of ConcreteService2 */ }
}

// register /IService/SomeOperation
endpoints.MapGrpcService<ConcreteService1>();

// /IService/SomeOperation is already registered by ConcreteService1
endpoints.MapGrpcService<ConcreteService2>();

Boths ConcreteService1 and ConcreteService2 try to register the same endpoint /IService/SomeOperation and it leads to a naming conflict. For details see ServiceModel.Grpc service and operation names.

Solution

Remove ServiceContract attribute from IService.

// remove [ServiceContract]
public interface IService
{
    [OperationContract]
    Task SomeOperation();
}

// register endpoint /IConcreteService1/SomeOperation
endpoints.MapGrpcService<ConcreteService1>();

// register endpoint /IConcreteService2/SomeOperation
endpoints.MapGrpcService<ConcreteService2>();

If an interface does not contain [ServiceContract], the service name for each defined operation comes from the root [ServiceContract] interface, in the provided example root interfaces are IConcreteService1 and IConcreteService2

@max-ieremenko max-ieremenko added the enhancement New feature or request label Jan 29, 2022
@max-ieremenko max-ieremenko added this to the 1.4.3 milestone Jan 29, 2022
@max-ieremenko max-ieremenko self-assigned this Jan 29, 2022
max-ieremenko added a commit that referenced this issue Jan 30, 2022
@max-ieremenko
Copy link
Owner Author

released in version 1.4.3, see example and service and operation bindings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant