ivaylokenov / MyTested.AspNetCore.Mvc

Fluent testing library for ASP.NET Core MVC.
https://docs.mytestedasp.net/
Other
1.73k stars 175 forks source link

UseServiceProviderFactory(new AutofacServiceProviderFactory()) in IsRunning ? #404

Open amunim opened 2 years ago

amunim commented 2 years ago

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.