我有一个ASP.NET MVC应用程序,我使用Ninject进行DI,我使用输出缓存系统。但是我需要从我的业务层(服务)中获取一些信息,但我不知道如何将我的服务注入到GetVaryByCustomString方法中。但是我不知道如何将我的服务注入到GetVaryByCustomString方法中。你有什么办法?
public override string GetVaryByCustomString(HttpContext context, string arg)
{
//I need some services here, for example product service.
//I need like this
//var prodManager = Ninject.Get<IProductService>();
//prodManager.ToSomeMethod();
}
我已经找到了我的解决方案。
public override string GetVaryByCustomString(HttpContext context, string arg)
{
var prodManager = DependencyResolver.Current.GetService<IProductService>();
prodManager.ToSomeMethod();
}