ASP.NET Core DependencyResolver

后端 未结 7 743
故里飘歌
故里飘歌 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:51

    Service available in Asp.net core, its within HttpContext

    this.HttpContext.RequestServices
    

    By using this service, it is possible to get service. and also you can use GetService method to retrieve the dependencies by specifying the type of the dependency:

    this.HttpContext.RequestServices.GetService(typeof(ISomeService));
    

提交回复
热议问题