我如何用Ninject将我的服务注入到GetVaryByCustomString中?

问题描述 投票:0回答:1

我有一个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();
    }
c# asp.net-mvc dependency-injection ninject ninject.web.mvc
1个回答
1
投票

我已经找到了我的解决方案。

public override string GetVaryByCustomString(HttpContext context, string arg)
{
   var prodManager = DependencyResolver.Current.GetService<IProductService>();
   prodManager.ToSomeMethod();
}
© www.soinside.com 2019 - 2024. All rights reserved.