我使用过 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>