Does Castle Windsor support applying setter injection to existing service instances? I have a case in which I have no control over the creation of certain class instances while I do need to resolve dependencies for them. This rules out constructor injection but leaves the door open for setter injection since I can intercept the new instances right after they're created.
I know Castle Windsor supports setter injection out of the box, I just don't know whether its possible (and if so: how) to leverage it explicitly without using the Resolve
method.
I know as well that such thing is possible in StructureMap, using the ObjectFactory.BuildUp
method so that raises my hope of finding an equivalent in Castle Windsor.
In case you are wondering, I'm applying dependency injection to pages in ASP.NET WebForms, providing a custom PageHandlerFactory
. I don't want to go down the path of trying to create the page handler myself, I should leave that to the base implementation in the PageHandlerFactory
class.
public class CustomPageHandlerFactory : PageHandlerFactory
{
public override IHttpHandler GetHandler(HttpContext context, string requestType, string virtualPath, string path)
{
IHttpHandler handler = base.GetHandler(context, requestType, virtualPath, path);
Page page = handler as Page;
if (page == null)
{
return handler;
}
// Resolve dependencies using setter injection...
return page;
}
}