Serge Gusev
Serge Gusev

Reputation: 1

Autofac to NetCoreApp1.1 conversion

Good day.

I'm trying to convert one .NET 4.5 class library to .NETCoreApp 1.1 and stuck on one peace of code:

public virtual ILifetimeScope Scope()
{
    return AutofacDependencyResolver.Current.RequestLifetimeScope;
}

AutofacDependencyResolver was declared in Autofac.Integration.Mvc in .NET 4.5 but looks like it does not exist in .NETCoreApp 1.1.

So, how can I return the current ILifetimeScope now?

Thank you in advance, Serge

Upvotes: 0

Views: 34

Answers (1)

Travis Illig
Travis Illig

Reputation: 23924

ASP.NET Core is a very, very different beast than classic ASP.NET on a full .NET Framework. It's much more like Web API (where there is no "central dependency resolver") than like MVC.

I'd recommend checking out the ASP.NET Core integration documentation, especially the section on "Differences From ASP.NET Classic" which contains this bullet (among others):

No more DependencyResolver. Other ASP.NET integration mechanisms required setting up a custom Autofac-based dependency resolver in various locations. With Microsoft.Extensions.DependencyInjection and the Startup.ConfigureServices method, you now just return the IServiceProvider and “magic happens.” Within controllers, classes, etc. if you need to manually do service location, get an IServiceProvider.

Upvotes: 1

Related Questions