我们可以在统一容器中为单例实例定义超时吗?

时间:2020-01-02 13:22:33

标签: wcf unity-container

我在unity服务应用程序中使用WCF容器。 NuGet软件包5.11.1。当前,我使用ContainerControlledLifetimeManager生命周期管理器(单例),它在解析后会返回相同的对象。

我想给生存期管理器超时,以便在2分钟的特定时间后创建一个新对象。可以做到团结吗?

container.RegisterType<IMyInterface, MyConcrete>(); // register the interface
container.Resolve<IMyInterface>(); // it will create the object at first time
container.Resolve<IMyInterface>(); // it will return the same object object
// after 2 minutes 
container.Resolve<IMyInterface>(); // it will create a new object object again

0 个答案:

没有答案