Injecting into existing objects

Jul 29, 2011 at 6:50 PM
Edited Jul 29, 2011 at 6:54 PM

Is it possible to inject property dependancies to existing objects?

For example, I'm trying to inject dependancies into ASP.NET MVC Action Filters. For this purpose I created descendant class of ControllerActionInvoker and trying to override GetFilters method;

public class UnityActionInvoker : ControllerActionInvoker

{

IUnityContainer container;

public IUnityContainer Container { get { return container; } }

public UnityActionInvoker(IUnityContainer container)

{

this.container = container;

}

protected override FilterInfo GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)

{

var filters = base.GetFilters(controllerContext, actionDescriptor);

foreach (var filter in filters.AuthorizationFilters)

{

container. Inject(filter);

}

return filters;

}

}

So how is it possible to implement such Inject functionality with Unity?

Jul 29, 2011 at 11:25 PM

Use the IUnityContainer.BuildUp method.

 

Aug 18, 2011 at 7:21 PM
ctavares wrote:

Use the IUnityContainer.BuildUp method.

 


Thank you! Exactly what is need.