Question

Using castle windsor I add my HandleException Filter to the windsor container so I can get ILogger injected into my HandleExceptionFilter. I could not use LifestylePerWebRequest because I would get this error. I am wondering if my HandleExceptionFilter will be released correctly with it being Transient?

 public override IController CreateController(RequestContext requestContext, string controllerName)
        {

            var controller = base.CreateController(requestContext, controllerName);

            var c = controller as Controller;

            if (c != null)
            {
                c.ActionInvoker = new ErrorHandlingActionInvoker(_kernel.Resolve<IExceptionFilter>());
            }

            return controller;
        }
Was it helpful?

Solution

For transient component:

If you resolve them from the container using Resolve< >, they will live till you explictily release them.

If you create a component using the typed factory, the component will live till you call a Destroy method on the factory, or if you don't call one till the factory's lifetime is over.

If a transient component is resolve as dependency in the constructor or as setter on a property the component will live till the containing component lifetime is over.

This assumes the default release policy is used. In case the NoTracking delete policy is used, the container will not hold a reference to the component. (Using this is not recommended).

I hope this answers your question.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top