How do I find out from where a registration in the DryIoC container was invoked?

129 views Asked by At

I'm using DryIoC in (combination with ASP.NET Core) and am getting a DryIoc.ContainerException seemingly because of a wrong registration.

Registering implementation type Microsoft.Extensions.Logging.ConsoleFormatterConfigureOptions is not assignable to service type Microsoft.Extensions.Options.IConfigureOptions<Microsoft.Extensions.Logging.Console.JsonConsoleFormatterOptions>.'

I created a DryIoC container and using it in the WebBuilder:

WebApplicationBuilder? builder = WebApplication.CreateBuilder( args );
builder.Host.UseServiceProviderFactory(
    new DryIocServiceProviderFactory(DiContainer));

How can I find out, where this registration is done?

Or someone can directly tell me what to do to get rid of the error...

Update:

I found that the registration comes from Microsoft.Extensions.Logging.ConsoleLoggerExtensions. But still do not know why.

Here is the example code if you start with a new asp.net core project:

using DryIoc.Microsoft.DependencyInjection;

namespace WebApplication1
{
    public class Program
    {
        public static void Main( string[] args )
        {
            var container = new DryIoc.Container();

            var builder = WebApplication.CreateBuilder( args );
            builder.Host.UseServiceProviderFactory( new DryIocServiceProviderFactory( container ) );

            var app = builder.Build();
        }
    }
}

builder.Build() raises the exception.

Thanks

2

There are 2 answers

1
Mathias Rotter On BEST ANSWER

Problem is caused by using older versions of DryIoc.dll (4.0.5) and DryIoc.Microsoft.DependencyInjection (3.0.3) with .NET 8.

After upgrading to latest stable versions the issue is gone.

Many thanks to Guru Stron for the support!

0
Amelie On

Based on the error message, it seems that there is a registration issue with the implementation type Microsoft.Extensions.Logging.ConsoleFormatterConfigureOptions and the service type Microsoft.Extensions.Options.IConfigureOptions.

To find out where this registration is done, you can search for the implementation type Microsoft.Extensions.Logging.ConsoleFormatterConfigureOptions in your codebase. Look for any calls to the Register method or any other registration methods of the container where this implementation type is being registered.

Once you find the registration, you can check if the service type is correct and update it if necessary. Make sure that the service type Microsoft.Extensions.Options.IConfigureOptions is being registered correctly for the implementation type Microsoft.Extensions.Logging.ConsoleFormatterConfigureOptions.