I would like to register two services, A
& B
, with different lifetimes.
My use case is simmilar to "Browser" and "Tabs".
I have one scope over the executable lifetime (browser) and one "subScope" for each tab.
I want A
to be a singleton in the browser scope (browser lifetime).
Now i would like to resolve a different B
, but the same A
in every tab.
I've read the GitHub docs, but it looks like I would get a new A
in every tab.
Pseudo-code would look like this:
var container = new Container();
container.Register<A>(Reuse.Scoped);
container.Register<B>(Reuse.Scoped);
using (var browserScope = container.OpenScope())
{
using (var tabScope1 = browserScope.OpenScope())
{
var a1 = tabScope1.Resolve<A>();
var b1 = tabScope1.Resolve<B>();
}
using (var tabScope2 = browserScope.OpenScope())
{
var a2 = tabScope2.Resolve<A>();
var b2 = tabScope2.Resolve<B>();
}
}
I would like a1
and a2
to be resolved as the same instance.
How can i accomplish this?