Net Core Dependency Injection for Non-Controller

后端 未结 4 576
挽巷
挽巷 2020-12-05 07:40

Seems crazy that something like this is causing me such a headache. But here it is:

How do you use the built-in dependency injection for net core for a non-controll

4条回答
  •  没有蜡笔的小新
    2020-12-05 08:26

    There are actually many ways to inject your dependency, the most common one you will find on controllers. There is also this variant

    var someService = (ISomeService)HttpContext.RequestServices.GetService(typeof(ISomeService));
    

提交回复
热议问题