z4kn4fein / stashbox

A lightweight, fast, and portable dependency injection framework for .NET-based solutions.
https://z4kn4fein.github.io/stashbox
MIT License
140 stars 10 forks source link

Enhancement: Allow factory methods to "overwrite" Scope or Disposal-Tracking behaviour #113

Closed schuettecarsten closed 2 years ago

schuettecarsten commented 2 years ago

I use factory methods to create instances of some types and also return "cached" instances if they are valid for the current program state. It would be great if it is possible to tell Stashbox from a factory methods that the currently returned instance should not be added ot the scope (overwrite to Transient) or should not be dispose-tracked, because it might be cached somewhere. Currently, it is only possible to disable disposal tracking for the whole registration, but not decide this per returned instance from the factory method.

I know that this is a very special enhancement.... :-)

z4kn4fein commented 2 years ago

Hi @schuettecarsten, thanks for reaching out! This is a bit bigger request and I need some time to think about the possible solutions. I can't promise anything for now, just that I'll think about it.

z4kn4fein commented 2 years ago

Hi @schuettecarsten, I published a new pre-release version that contains the proposed solution for this issue. The IRequestContext which is accessible in factory delegates got a new method ExcludeFromTracking(instance). Passing your cached instance will exclude it from disposing.

Please let me know your thoughts!

schuettecarsten commented 2 years ago

Thank you, as I compile Stashbox myself at the moment, the prereleased version is based on the current dev branch?

z4kn4fein commented 2 years ago

Yes, it was published from the current dev branch.

github-actions[bot] commented 2 years ago

This issue is marked stale because it has been open for 90 days with no activity.

github-actions[bot] commented 2 years ago

This issue was closed due to no activity.