You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
@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
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:
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 theGetCustomAttributes(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?
The text was updated successfully, but these errors were encountered: