Spring.Net:注入ApplicationContext / ObjectFactory本身

发布于 2024-09-26 15:15:45 字数 824 浏览 8 评论 0原文

有没有办法将当前正在执行的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

傲影 2024-10-03 15:15:45

只需让您的类实现 IApplicationContextAware 即可让您自动注入当前的 IApplicationContext 。

just make your class implement IApplicationContextAware that should get you the current IApplicationContext injected automagically.

殊姿 2024-10-03 15:15:45

怎么样:

<object id="SpringActionInvoker" type="xxx.SpringActionInvoker, xxx" />

然后:

public class SpringActionInvoker : ControllerActionInvoker
{
    protected override FilterInfo GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
    {
        IObjectFactory objectFactory = ContextRegistry.GetContext();
        //use objectFactory to inject dependencies into filters
    }
}

How about:

<object id="SpringActionInvoker" type="xxx.SpringActionInvoker, xxx" />

And then:

public class SpringActionInvoker : ControllerActionInvoker
{
    protected override FilterInfo GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
    {
        IObjectFactory objectFactory = ContextRegistry.GetContext();
        //use objectFactory to inject dependencies into filters
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文