开发者

StructureMap reset singleton instance

开发者 https://www.devze.com 2023-01-10 15:05 出处:网络
I have created a bootst开发者_JAVA技巧rapper which creates a singleton object.Under some circumstances, I wish to have the singleton recreated... I have tried:

I have created a bootst开发者_JAVA技巧rapper which creates a singleton object. Under some circumstances, I wish to have the singleton recreated... I have tried: ObjectFactory.Model.For().EjectAndRemoveAll();

Does anyone know how I can remove current instances for a specific type, without removing the rules that govern its creation. e.g. ObjectFactory.EjectAllInstancesOf will remove the config rules as well.

thanks for your help


One way would be to define a lifecycle by overriding ILifeCycle which ejects the cached instance when your conditions are met.

You could start by looking at the implementation of the singleton lifecycle in the structuremap source and perhaps inherit or modify that.

0

精彩评论

暂无评论...
验证码 换一张
取 消