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

Missed custom attribute in SubService interface #330

Open
Dona278 opened this issue Jul 3, 2024 · 1 comment
Open

Missed custom attribute in SubService interface #330

Dona278 opened this issue Jul 3, 2024 · 1 comment

Comments

@Dona278
Copy link

Dona278 commented Jul 3, 2024

We use custom attribute to decorate grpc service class methods in order to do something by wrapping the method implementation through asp net core middleware.
All custom attributes of a method of a controller (or of a method of the grpc service) will be available through aspnet core endpoint's metadata.

So, we have this scenario:

[SubService]
public interface ITestSubService 
{
   [Operation]
   ValueTask DoSomethingCommon(CallContext context);
}

[Service]
public interface ITestService : ITestSubService 
{
   [Operation]
   ValueTask DoSomethingSpecific(CallContext context);
}

internal class TestService : ITestService 
{
   [CustomAttribute]
   public ValueTask DoSomethingCommon(CallContext context) 
   {
      // ...
   }

   [CustomAttribute]
   public ValueTask DoSomethingSpecific(CallContext context) 
   {
      // ...
   }
}

And all worked good until today when we added the custom attribute also to the method inherited by the subservice interface DoSomethingCommon and we noticed that the attribute will never added to the endpoint's metadata collection.
All other services and methods which have the attributes works good.

By debugging we encontered the "issue" here.
The bindCtx is created in the foreach loop of each type which methods have to be bound (so both interfaces), but the parameters passed are always the same and in the scenario above the ServiceBindContext always have the ITestService as contract and TestService as type even if the method to bind is the method of ITestSubService which lead in a method not found here which never calls the GetCustomAttributes(inherit: true) of the type implementation.

Attempt to change
var bindCtx = new ServiceBindContext(serviceContract, serviceType, state, binderConfiguration.Binder);
to
var bindCtx = new ServiceBindContext(typeToBindItsMethods, serviceType, state, binderConfiguration.Binder);
all tests passed and all services work without issues, but it is correct? We missed something?

@Dona278
Copy link
Author

Dona278 commented Sep 29, 2024

@mgravell sorry for mentioned you, but can anyone leave a feedback about this? It's very annoyng to copy-paste a workaround code when necessary. Thank yoi

Dona278 added a commit to hexesoft/protobuf-net.Grpc that referenced this issue Oct 17, 2024
- Used protobuf-net 3.2.30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant