Ninject w的一个MVC3 / ASMX Web服务/ Ninject 3环境 [英] Ninject w/ ASMX web service in a MVC3/Ninject 3 environment
问题描述
我在寻找合并经典的ASMX Web服务进入我的MVC3环境的最佳方法。我想两者之间共享内核/容器。
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.
在与ASP.NET Web表单过去我能够使用以下命令:
In the past with ASP.NET web forms I was able to use the following:
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class Service : WebServiceBase
{
[Inject]
public IContextProvider ContextProvider { get; set; }
...
这用旧Ninject.Web共享使用KernelContainer被WebServiceBase,PageBase等之间共享内核等。
This used the older Ninject.Web to shared the kernel using the KernelContainer that was shared between WebServiceBase, PageBase, etc. etc.
现在我已经使用Ninject.Web.MVC有一个MVC3应用程序,我需要一个较旧的Web服务在同一空间的功能,使用相同的内核/绑定。我一直没能找到在得到这样的启动和运行一个安装的任何信息。
Now I've got a MVC3 application using Ninject.Web.MVC and I need an older web service to function in the same space, using the same kernel/bindings. I haven't been able to find any information on getting a setup like this up and running.
有没有人有任何想法,样品或职位,他们可以指向我(除了不使用ASMX Web服务)?
Does anyone have any ideas, samples, or posts they can point me to (other than don't use asmx web services)?
推荐答案
MVC框架支持它与Ninject集成了MVC的DependencyResolver。虽然它不是可以定义ASMX Web服务的定义工厂,你可以做到以下几点:
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.
这篇关于Ninject w的一个MVC3 / ASMX Web服务/ Ninject 3环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!