如何使用Ninject将我的服务注入GetVaryByCustomString



我有一个ASP.NET MVC应用程序,我使用Ninject作为DI,我使用输出缓存系统。但是我需要从我的业务层(服务(获取一些信息。但我不知道如何将我的服务注入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();
}

最新更新