grpc/grpc-dotnet

DefaultServiceActivator<T> is not using custom IServiceProvider

DavidHoechtlJH opened this issue · 0 comments

What version of gRPC and what language are you using?

2.65.0

What operating system (Linux, Windows,...) and version?

Windows

What runtime / compiler are you using (e.g. .NET Core SDK version dotnet --info)

.NET SDK:
Version: 8.0.400

What did you do?

I register my custom IServiceProvider in my Asp.NetCore Kestrel server via:

webApplicationBuilder.Host.UseServiceProviderFactory( new MyCustomServiceProvider( Container ) );
// Container is a Autofac IContainer instance
(i´m using a hybrid system that combines the microsoft dependency container with a built Autofac.Container)

What did you expect to see?

DefaultServiceActivator should us the MyCustomServiceProvider to resolve grpc services

What did you see instead?

DefaultServiceActivator uses a different instance of IServiceProvider (looks like the default microsoft dependency IServiceProvider)

Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).
on service creation i´m getting following exception:

System.InvalidOperationException: Unable to resolve service for type 'MyService' while attempting to activate 'OtherService'. at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ThrowHelperUnableToResolveService(Type type, Type requiredBy) at lambda_method4900(Closure, IServiceProvider, Object[]) at Grpc.AspNetCore.Server.Internal.DefaultGrpcServiceActivator1.Create(IServiceProvider serviceProvider) at Grpc.Shared.Server.UnaryServerMethodInvoker3.Invoke(HttpContext httpContext, ServerCallContext serverCallContext, TRequest request) --- End of stack trace from previous location --- at Grpc.AspNetCore.Server.Internal.CallHandlers.UnaryServerCallHandler3.HandleCallAsyncCore(HttpContext httpContext, HttpContextServerCallContext serverCallContext) at Grpc.AspNetCore.Server.Internal.CallHandlers.ServerCallHandlerBase3.<HandleCallAsync>g__AwaitHandleCall|8_0(HttpContextServerCallContext serverCallContext, Method2 method, Task handleCall)