New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Transitions do not honour service Scope #67
Comments
To resolve the first issue, we need to register the respective The reason that we use Singletons currently is so that we can get the instance when a Transition is requested, and perform the swap. Going forward, we are going to need to maintain a Transition Register to track active instances of the proxies. |
The second part of this issue is Snapshotting. Given the following example: services.AddTransient<IFoo, Foo>().AsTransitional();
services.Snapshot<IFoo>();
services.AddSingleton<Bar, Bar>(); // self-bind
services.Transition<IFoo, Bar>(); With the current architecture, we have a problem in that the transition proxy is not able to honour both the scope of To resolve this, we will need to maintain a Snapshot Register, which is able to store the snapshotted services for a proxy. (This is complicated and has many scenarios to consider such as WeakReferencing the transients so they can naturally fall out of scope!) |
This issue can also manifest itself when resolving an interface implementing |
This has been made |
We've discussed this internally and come up with a plan. The current flow for transitions (for comparison to proposed flow below):
When the interface is requested directly The proposed flow and subsequent results:
When the interface is requested directly |
The above process (diagram in previous comment) will offer some guide lines as to how compose handles different implementation techniques, however the code turned out to be far more involved (beyond the scope of a quick diagram). To get an idea of how this works, examine the
There are also a series of behavioural tests available in |
This issue has multiple parts, which I'll add as separate comments once I get my head around them.
The first issue is that
ITransition<T>
s which are the wrapper interfaces used to register dynamic proxies, are always registered as Singletons, regardless of the original service registration.For example:
This will register
<IFoo, Bar>
as Transient, then register an<ITransition<IFoo>>
as Singleton.When attempting to resolve an
IFoo
, the singletonITransition<IFoo>
will actually be resolved instead, and theBar
will be resolved independently and injected into the proxy.This means, although we honour the scope when resolving the
Bar
, the Singleton proxy will maintain a reference toBar
forever, extending the life span (that's bad).The text was updated successfully, but these errors were encountered: