views:

27

answers:

2

Hi

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
    }
}
A: 

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
    }
}
Darin Dimitrov
I want to put SpringActionInvoker in a utility class and I don't always create the ObjectContext with the app.config and ContextRegistry
Fabiano
A: 

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

Sebastian Piu