asp.net - 在 MVC3/Ninject 3 环境中使用 ASMX Web 服务的 Ninject

标签 asp.net ninject asmx ninject.web.mvc ninject.web

我正在寻找将经典 asmx Web 服务整合到我的 MVC3 环境中的最佳方式。我希望在两者之间共享内核/容器。

在过去使用 ASP.NET Web 表单时,我能够使用以下内容:

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class Service : WebServiceBase
{
    [Inject]
    public IContextProvider ContextProvider { get; set; }
...

这使用旧的 Ninject.Web 来共享内核,使用在 WebServiceBase、PageBase 等之间共享的 KernelContainer 等。

现在我有一个使用 Ninject.Web.MVC 的 MVC3 应用程序,我需要一个较旧的 Web 服务在相同的空间中运行,使用相同的内核/绑定(bind)。我无法找到有关启动和运行这样的设置的任何信息。

有没有人有任何想法、示例或帖子可以指向我(除了不使用 asmx Web 服务)?

最佳答案

MVC 框架支持与 Ninject for MVC 集成的 DependencyResolver。尽管无法为 ASMX Web 服务定义自定义工厂,但您可以执行以下操作:

public class Service : WebService
{
  public IContextProvider ContextProvider {get;set;}

  public Service()
  {
    ContextProvider = DependencyResolver.Current.GetService<IContextProvider>();
  }
}

虽然您不能在构建服务期间注入(inject)依赖项,但您可以在构造函数中自己解决它们。

关于asp.net - 在 MVC3/Ninject 3 环境中使用 ASMX Web 服务的 Ninject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12378026/

相关文章:

asp.net - VB.Net 中的 XPath 表达式 - 如何搜索包含 unicode 字符的 xml 文档

c# - ASP MVC : Weird white spaces on the textbox whenever i try to edit a record

c# - Web Api 2 RESTFUL 图片上传

dependency-injection - 使用 Ninject 2.0 避免 XNA 中的循环依赖

c# - .NET 2.0 Web 服务 WSDL 错误元素被忽略?

c# - 为多个服务设置 ASMX 命名空间的最佳方法

c# - 我正在尝试使用 SQL 语句中下拉菜单中的 selectedItem 来填充 C# asp.net 中的文本框

asp.net-mvc - MVC Ninject 我不想引用数据层而只想引用服务层

ninject - Ninject 中 .Resolve 和 .Get 的区别

asp.net - 发布到 ASMX 服务并返回 jQuery 对象