Closed darkcamper closed 7 years ago
@darkcamper , ultimately the problem comes down to you created one registration with a lifestyle but want to use the same registration in two different ways.
In one situation you want the container to create Dispoable as a sington per scope. In the other situation you want the container to create a transient with no disposal tracking.
Probably the easiest solution is to do a second export of the same type but use the AsKeyed and ExtenallyOwned (so instances aren't tracked) in lue of the lifestyle. Then you can do a Locate(withKey: "key");
Later today I maybe able to put together a demo of what I'm thinking but at the moment I'm on feeding and diaper duty.
I've added two unit tests as examples of what I was thinking at the bottom here.
I've also opened issue #99 to support using Func<T>
I was pretty sure I would need another export for the factories but I didn't realize the key was in the keys (no pun intended). I've read the new unit tests you've made, and now it's all clear to me.
Thank you @ipjohnson !
@ipjohnson
Hi!
I have some IDisposable implementations for which I only want a single instance created per named scope ( using SingletonPerNamedScope works ok for this). But I also need sometimes to inject a factory for these IDisposable that would create always new instances that are not tracked by the scope (and threfore not disposed when the scope is disposed).
Here a small sample of what I want to do:
I've thought (and tried) of using Func<Scoped> and Func<Owned> but they don't really behave the way I need.
Is there any combination of special types, lifestyles or other configuration options that would work in this case?
Thanks.