I encountered the same thing in my application (.Net Core 3.1)
I wanted to get the Container and resolve registered services.
In .Net Core 3.1 you can't simply change Startup.ConfigureServices
method to return IServiceProvider
as it was in previous versions
So, to get the services you need in your Startup void Configure(IApplicationBuilder app)
method call app.ApplicationServices.GetAutofacRoot()
this will return ILifetimeScope instance you can use to resolve services
Note. Consider that saving this instance globally is not the best practice
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
//app middleware registrations
//...
//
ILifetimeScope autofacRoot = app.ApplicationServices.GetAutofacRoot();
var repository = autofacRoot.Resolve<IRepository>();
}