2016-10-25 47 views
1

我試圖安裝一個裝飾圍繞IDisposable分貝方面:DryIoc:無法弄清楚如何註冊IDisposable的裝飾物

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.DecoratortrackDisposableTransient

回答

2

該設置不適用於每個裝飾註冊(從最新的DryIoc v2.8.3開始)。

現在您需要指定裝飾器的非瞬時重用。

隨意籌集到的一個問題:https://bitbucket.org/dadhi/dryioc

+0

我在DryIoc絕對的初學者,所以你不介意,解釋如何? 有什麼副作用? –

+1

瞬態跟蹤功能有點爭議,首先被引入以符合新的.NET Core MS.DI.所以我儘可能地限制了它,看看它是如何發展的。將這添加到轉印商(希望)是沒有問題的。但首先問題是:你的裝飾服務是否被重用? – dadhi

+0

我不確定在DI上下文中_reused_是什麼意思,但每當我對數據庫進行查詢時都會使用它。 –