Search code examples
c#asp.net-mvcdependency-injectionninjectninject.web.mvc

How Can I Inject My Services To GetVaryByCustomString With Ninject


I have an ASP.NET MVC application, i use Ninject for DI and i use output cache system. But i need to take some informations from my business layer(services). But i don't know how can i inject my services to GetVaryByCustomString method. What's your solution?

    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();
    }

Solution

  • I've found my solution.

    public override string GetVaryByCustomString(HttpContext context, string arg)
    {
       var prodManager = DependencyResolver.Current.GetService<IProductService>();
       prodManager.ToSomeMethod();
    }