ASP.NET Core DependencyResolver

后端 未结 7 724
故里飘歌
故里飘歌 2020-12-15 19:20

In ASP.NET MVC 5 is possible to obtain some dependency through DependencyResolver.Current.GetService(). Is there something similar in ASP.NET Core?

7条回答
  •  南方客
    南方客 (楼主)
    2020-12-15 19:38

    I think this could be a good start:

    That's official documentation for dependency injection for asp.net 5.

    Dependency injection is now built into asp.net 5 but you are free to use other libraries like autofac. The default one is working fine for me.

    In your starup class, you have a method like this

    public void ConfigureServices(IServiceCollection services)
    {
    
        //IServiceCollection acts like a container and you 
        //can register your classes like this:
    
        services.AddTransient();
        services.Singleton();
        services.AddScoped();
    
    }
    

    From:

    DependencyResolver Asp.net 5.0

提交回复
热议问题