MyTested.AspNetCore.Mvc icon indicating copy to clipboard operation
MyTested.AspNetCore.Mvc copied to clipboard

UseServiceProviderFactory(new AutofacServiceProviderFactory()) in IsRunning ?

Open amunim opened this issue 2 years ago • 0 comments

I want to use Autofac in my project but can't add this. If I use the sample in your issues, autofac does not register my generic mediator Handlers, i.e. WithServices(s => s.AddAutofac()) calls ConfigureTestContainer but somehow Controller throws Handler not Found exception.

While in my Program.cs, I have:

Host.CreateDefaultBuilder(args)
                .UseServiceProviderFactory(new AutofacServiceProviderFactory())
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });

which calls the same

public void ConfigureContainer(ContainerBuilder builder)
        {
            builder.RegisterGeneric(typeof(Application.Main.Main.Handler<>)).AsImplementedInterfaces();
            builder.RegisterGeneric(typeof(Main<,,>.Handler)).AsImplementedInterfaces();
            builder.RegisterGeneric(typeof(Main<,>.Handler)).AsImplementedInterfaces();
        }

I only renamed it to ConfigureTestContainer with same lines and invoke base.ConfigureContainer(builder);, and an error is thrown Only in tests.

amunim avatar Feb 01 '22 06:02 amunim