Spring.Net:注入ApplicationContext / ObjectFactory本身
有没有办法将当前正在执行的 IObjectFactory 或 ApplicationContext 作为对象的依赖项传递?例如,
<object id="SpringActionInvoker" type="xxx.SpringActionInvoker, xxx">
<constructor-arg ref="reference_to_the_ApplicationContext_or_ObjectFactor_that_is_executing" />
</object>
我想将它用于我的 Asp.Net MVC ControllerActionInvoker 的 Spring.Net 实现,该实现将被注入到控制器中
public class SpringActionInvoker : ControllerActionInvoker
{
private IObjectFactory objectFactory;
public SpringActionInvoker(IObjectFactory objectFactory)
{
this.objectFactory = objectFactory;
}
protected override FilterInfo GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
{
//use objectFactory to inject dependencies into filters
}
}
Is there a way to pass the IObjectFactory or the ApplicationContext that is currently executing as dependency to an object? For example
<object id="SpringActionInvoker" type="xxx.SpringActionInvoker, xxx">
<constructor-arg ref="reference_to_the_ApplicationContext_or_ObjectFactor_that_is_executing" />
</object>
I want to use it for my Spring.Net implementation of the Asp.Net MVC ControllerActionInvoker that will be injected to the controllers
public class SpringActionInvoker : ControllerActionInvoker
{
private IObjectFactory objectFactory;
public SpringActionInvoker(IObjectFactory objectFactory)
{
this.objectFactory = objectFactory;
}
protected override FilterInfo GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
{
//use objectFactory to inject dependencies into filters
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需让您的类实现 IApplicationContextAware 即可让您自动注入当前的 IApplicationContext 。
just make your class implement
IApplicationContextAware
that should get you the current IApplicationContext injected automagically.怎么样:
然后:
How about:
And then: