volosoft / castle-windsor-ms-adapter

Castle Windsor ASP.NET Core / Microsoft.Extensions.DependencyInjection Adapter
https://www.nuget.org/packages/Castle.Windsor.MsDependencyInjection
MIT License
85 stars 29 forks source link

Runtime error when using the new .NET 8 Keyed Services in ASP.NET Boilerplate #48

Open DamienLaw opened 3 months ago

DamienLaw commented 3 months ago

I encountered the following runtime error when using the new .NET 8 Keyed Services in ASP.NET Boilerplate project.

System.InvalidOperationException: This service descriptor is keyed. Your service provider may not support keyed services.

This can be easily reproduced by adding the following line in Startup.cs file.

public void ConfigureServices(IServiceCollection services)
{
    services.AddKeyedTransient<IMyKeyedService, MyKeyedService>("test");
}

Run the project and you'll be greeted with this: image

I have tracked the problem to the following method on line 109 and potentially 130: https://github.com/volosoft/castle-windsor-ms-adapter/blob/641252c3b60dd8affeb5247b3c890564d918596a/src/Castle.Windsor.MsDependencyInjection/WindsorRegistrationHelper.cs#L105-L149

The statement serviceDescriptor.ImplementationInstance and serviceDescriptor.ImplementationType is throwing the exception. More info can be found here.

I'll just take an excerpt from the issue above: image

image

The images above is a snippet of dotnet source code where accessing the getter of property ImplementationInstance and ImplementationType will throw the exception under certain condition.

This has been reported in the new abp.io framework. https://github.com/abpframework/abp/issues/18708

I'm actually trying to use AddStandardResilienceHandler() in Microsoft.Extensions.Http.Resilience before encountering this issue:

services.AddHttpClient<IMyService, MyService>()
    .AddStandardResilienceHandler();
maliming commented 3 months ago

Waiting https://github.com/castleproject/Windsor/pull/668

TheDutchDev commented 3 months ago

We're running into the same issue here. Would really like to have this PR added asap