Open jnm2 opened 2 years ago
I'm not sure about this. At the moment StrongInject only contains types that help with DI itself. Do we want to start adding in types which aren't actually helpful for DI, but for testing code which uses it, especially when it's super simple to write this yourself?
I would look at this as having to do with the definition of Owned<T>
as a library type and as being completely separate from the source generator. What would it look like if the BCL maintained this type, or someone else?
On the other hand it's not a huge deal if I copy and paste this file as needed.
Updated the definitions. Not sure where I thought I was going with disposeFirst
. 😆
Once a lot of a codebase has necessarily taken a dependency on
Owned<T>
so that StrongInject can wire everything up, many places remain that need to create their own Owned instances. This is handy for many tests and smaller executables in a project that don't really need StrongInject and can do their own wiring with a few calls.Instead of:
new Owned<SomePotentiallyLongTypeName>(value, () => { })
Friendly:Owned.WithoutDisposal(value)
Instead of:
new Owned<SomePotentiallyLongTypeName>(value, value.Dispose)
Friendly:Owned.WithDisposal(value)
Instead of:
new Owned<T>(value, () => (value as IDisposable)?.Dispose())
Friendly:Owned.WithDisposal(value)
Instead of:
new Owned<SomeType>(value, () => { value.Dispose(); dependency1.Dispose(); dependency2.Dispose(); })
Friendly:Owned.WithDisposal(value, dependency1, dependency2)
or Friendly:Owned.WithDisposal(value, alsoDispose: new[] { dependency1, dependency2 })
Here's a rough draft for what I've already found useful, and I'm happy to do the implementation:
An AsyncOwned static class would be similar.