How to get Microsoft.AspNet.Http.HttpContext instance in Class Constructor using DI

前端 未结 4 1144
北海茫月
北海茫月 2021-01-03 23:18

I am building a throwaway application in MVC 6 and experimenting with different architectures for dependencies.

The problem I am facing is how to create a custom \'<

4条回答
  •  萌比男神i
    2021-01-03 23:59

    Why would you pass the HttpContext in the constructor? Why not directly access it wherever you want?

    public MyAppContext(IDataService dataService)
        {
           HttpContext mycontext = HttpContext.Current;
           //do stuff here with mycontext
        }
    

提交回复
热议问题