Replies: 4 comments 3 replies
-
I did more research and testing. The I still haven't found a solution to create something like The use case is this:
Ideally you'd inject Things that almost work:
|
Beta Was this translation helpful? Give feedback.
-
Hi @jods4 You probably need this one: https://github.com/dadhi/DryIoc/blob/master/docs/DryIoc.Docs/ReuseAndScopes.md#own-the-resolution-scope-disposal Here how could you write your And register it like this: For more info, you may look into https://github.com/dadhi/DryIoc/blob/1e4228c3d984e2b64aecd89d8c998ab0fb7b15a4/docs/DryIoc.Docs/FaqAutofacMigration.md |
Beta Was this translation helpful? Give feedback.
-
Interesting observation, I will test it and get back to you. |
Beta Was this translation helpful? Give feedback.
-
Just FYI, I replaced my |
Beta Was this translation helpful? Give feedback.
-
Other DIs have wrappers that affect Reuse, which are esp. useful combined with
Func
wrapper, for example:Scoped<T>: IDisposable
will create a new scope, provideT Value
in this scope, and dispose the whole scope when it's disposed itself.Owned<T>
contains a transientT Value
of a type that might be registered with Reuse other than transient. Because it's transient you're responsible for disposing it if required.They make more sense when you think of them as
Func<Scoped<T>>
andFunc<Owned<T>>
or similar.I have read the docs about Reuse and my understanding is that
Func<T>
actually works partly likeOwned
: its return value is never tracked for disposal; but it still reuses instances (multiple calls for a singleton per scope would always return the same instance), am I correct?First wrapper is probably easy to create as:
Although I'm not sure how to write
Owned
.PS: does
[ServiceKey]
work onRegisterDelegate
the same way it does in ctor parameters?Beta Was this translation helpful? Give feedback.
All reactions