Ninject w/ ASMX web service in a MVC3/Ninject 3 environment

后端 未结 1 607
猫巷女王i
猫巷女王i 2020-12-21 05:37

I\'m looking for the best way to incorporate a classic asmx web service into my MVC3 environment. I\'d like the kernel/container to be shared between the two.

In th

相关标签:
1条回答
  • 2020-12-21 06:20

    The MVC framework supports the DependencyResolver which integrates with Ninject for MVC. Although it is not possible to define a custom factory for ASMX web services, you could do the following:

    public class Service : WebService
    {
      public IContextProvider ContextProvider {get;set;}
    
      public Service()
      {
        ContextProvider = DependencyResolver.Current.GetService<IContextProvider>();
      }
    }
    

    While you cannot inject dependencies during construction of your service, you are able to resolve them yourself within the constructor.

    0 讨论(0)
提交回复
热议问题