【问题标题】:How to add ASP.NET MVC Controller in Spring.Net Application Context?如何在 Spring.Net 应用程序上下文中添加 ASP.NET MVC 控制器?
【发布时间】:2013-01-23 13:06:37
【问题描述】:

我正在使用 Spring.Net IOC 框架为我的 ASP.NET MVC 应用程序创建一个插件系统。 我已将控制器放在不同的程序集中,我需要将这些控制器动态添加到 Spring.Net 应用程序上下文中。

请指导我!!

我正在尝试像下面的文章那样实现插件系统,但我想使用 Spring.Net 而不是 Autofac。

http://www.codeproject.com/Articles/386674/ASP-NET-MVC-3-plug-in-architecture-using-Griffin-M

【问题讨论】:

  • 你遇到了什么问题?

标签: asp.net-mvc-3 spring.net griffin.mvccontrib


【解决方案1】:

我使用过 Spring.Net,并在其中使用 Application Context 访问了 Repository 对象 试试这个

IApplicationContext ctx = ContextRegistry.GetContext();
            dynamic controller= ctx.GetObject("MyController");

其中 MyController 是您在 controller.xml 文件中定义的控制器的 ID

<object
   id="MyController "
   type="Swapeteria.Web.Controllers.ItemPostController, Swapeteria.Web"
   singleton="false">
        <constructor-arg name="repository" ref="ItemRepository" />
        <constructor-arg name="bookRepository" ref="BookRepository" />
        <constructor-arg name="authorrepository" ref="authorRepository" />
        <constructor-arg name="publisherRepository" ref="PublisherRepository" />
        <constructor-arg name="itemMapper" ref="itemMapper" />
    </object>

【讨论】:

猜你喜欢
  • 2011-02-21
  • 2011-04-11
  • 1970-01-01
  • 2012-05-24
  • 2015-05-02
  • 1970-01-01
  • 2010-09-07
  • 2012-02-09
  • 2012-04-17
相关资源
最近更新 更多