我正在尝试围绕IDisposable
db上下文设置装饰器:
c.Register<IContext, DbContext>(setup: Setup.With(trackDisposableTransient: true));
// c.Register<IContext, ConsoleTimedContext>(setup: Setup.Decorator);
如果我取消注释最后一行,程序将抛出:
DryIoc.ContainerException: Registered Disposable Transient service Lib.DI.IContext with key {no key} and factory container won't be disposed by container. DryIoc does not hold reference to resolved transients, and therefore does not control their dispose. To silence this exception Register<YourService>(setup: Setup.With(allowDisposableTransient: true)) or set the rule Container(rules => rules.WithoutThrowOnRegisteringDisposableTransient()). To enable tracking use Register<YourService>(setup: Setup.With(trackDisposableTransient: true)) or set the rule Container(rules => rules.WithTrackingDisposableTransient())
à DryIoc.Throw.It(Int32 error, Object arg0, Object arg1, Object arg2, Object arg3)
à DryIoc.Container.ThrowIfInvalidRegistration(Factory factory, Type serviceType, Object serviceKey, Boolean isStaticallyChecked)
à DryIoc.Container.Register(Factory factory, Type serviceType, Object serviceKey, IfAlreadyRegistered ifAlreadyRegistered, Boolean isStaticallyChecked)
à DryIoc.Registrator.Register[TService,TImplementation](IRegistrator registrator, IReuse reuse, Made made, Setup setup, IfAlreadyRegistered ifAlreadyRegistered, Object serviceKey)
如何将Setup.Decorator
与trackDisposableTransient
混合?
答案 0 :(得分:1)
每个Decorator注册时无法使用该设置(截至最新的DryIoc v2.8.3)。
现在您需要为装饰器指定非瞬态重用。
提出问题