autofac/Autofac

ConfigureTestContainer not working with GenericHost

ssunkari opened this issue · 2 comments

I have Integration tests, which uses WebApplicationFactory net core interface.
Earlier netcore versions <3.0 has a way to override custom container registrations but once switched to generic host startup mode. The method override ConfigureTestContainer no longer get called. What do you recommend in terms of overriding the registrations in Autofac container for unit testing.

Below mehod is not called anymore in net core 3.

 .ConfigureTestContainer<ContainerBuilder>(containerBuilder =>
            { }

The order in which application bootstrap for IntegrationTests are:
Startup -> ConfigureServices
TestStartup -> ConfigureServices (Method Override if defined)
TestStartup -> ConfigureTestServices
Startup -> ConfigureContainer
TestStartup -> ConfigureTestContainer (Not called since netcore 3.0 upgrade with generic host usage)

There is a github issue on dotnet github page dotnet/aspnetcore#14907
but cannot find the solution.

Unfortunately, the hosting system and how it handles test containers is .NET Core code, not Autofac. If you find a reproducible bug or need an Autofac enhancement, please file an issue explaining it. Otherwise, please ask usage questions on StackOverflow or, as you've already done, file an issue with the appropriate group. Thanks!

For workarounds, see #1207