I can’t figure out how to use an AspNet Core 3.1 Web Api with Service Fabric and Autofac, and also how to have it ready for a TestServer to run for integration/functional testing.
The documentation is very incomplete.
Autofac documentation shows how to modify
Program.cs to build autofac container, but it does not mention anything about the Startup.cs class that all the web api have:
Also the only example that Autofac has for service fabric is not a web api: https://github.com/autofac/Examples/tree/master/src/ServiceFabricDemo
There are other questions without valid answers:
Service Fabric AspNet Core 3.1 Autofac WebHostBuilder
Does anybody have any example on how to achieve this?
I can achieve the following (please see my GitHub repository with the sample)
- Service fabric with stateless AspNet Core WebApi project (dotnet core 3.1)
- Using Microsoft Dependency Injection to register services
- Using TestServer to run integration tests on the http endpoint, and able to overwrite dependency injection registrations in a clean way without having to create another Startup class
I want the exact same, but using Autofac as DI container.
I can’t add Autofac to a
WebHostBuilder and the
ConfigureServices(IServiceCollection services) must be void as per AspNet Core 3.1+, so this is where I’m stuck. How to replace MS Dependency Injection in my sample