Closed mdissel closed 4 years ago
SingletonScope -> different instance per child container
SingletonPerObjectGraph -> Only singleton within the object graph, it will never be reused outside that call to scope.Locate where.
Thanks, so SingletonPerObjectGraph should be used for one instance per http request?
No you want SingletonScope as http request gets one scope for the lifetime of the request. Are you looking for a lifestyle that does one per child container and is reused for any containers the are created from the child container?
If so you want SingletonPerNamedScope and then when you create your child container with the same scope name.
Yes, for each tenant some services can be overruled/removed/added, see this sample with AutoFac.
https://github.com/dazinator/Dotnettency/blob/develop/src/Sample.AspNetCore30.RazorPages/Startup.cs
This is an interesting idea but ultimately I think it's probably really slow because child containers themselves are inherently much much slower than scopes where you can't change registration.
Grace is probably not going to perform very well, then again neither will Autofac or StructureMap.
But it seems to be a one-time only performance penalty for each child container, see https://github.com/dazinator/Dotnettency/blob/develop/src/Dotnettency.AspNetCore/Container/TenantContainerMiddleware.cs
I'm honestly surprised this works correctly and there are no weird side effects. I saw the AutofacAsync method and thought they were configuring the container mid request.
I guess if this works correctly then Grace should work the same as Autofac as that's what I modeled it after.
Are you putting together an adapter similar to what they have for Autofac/StructureMap?
Thanks for your time, but I'm switching to another framework.
What is the correct lifetime when I use the child containers for each tenant?
see https://github.com/dazinator/Dotnettency for a tenant based container
Singleton -> same instance in all child containers SingletonScope ?? -> asp.net core session request scope, resolved from child container SingletonPerObjectGraph -->different instance per child container
Thanks
Marco