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>();
}
}
question from:
https://stackoverflow.com/questions/66060619/how-to-remove-a-component-from-castle-windsor-5-0 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…