I am new to using Castle Windsor I have a couple of registered dependencies using Castle Windsor. I would like to dispose and remove one of these injected dependency at a particular time. How can I do this. My code is as follows: In the main function.
var container = new WindsorContainer();
container.Register(Component.For<ILogger>().ImplementedBy<logger>());
Please not that this dependency is not resolved but its Injected using Constructor.
public ILogger logger { get; set; }
public DoSomethin(
ILogger logger)
{
this.logger = logger;
}
Please Note that I am using castle windsor V5. The reason for doing this to clear the GC. Older versions have IKernel has a RemoveComponent method. which does not exists nowadays. Resolving component will be as follows:
public static class helper
{
public static T Resolve<T>()
{
return Instance.Resolve<T>();
}
}
Main class
public class Program{
public static void Main()
{
var obj1 = helper.Resolve<logger>();
}
}
Instance.Resolve<T>
hen I have used this helper else where in the application to insatiate an instance of logger so I will end up withvar obj1 = helper.Resolve<logger>();
@PhilDegenhardt – moe1792