You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SingletonPerKey disposing per request in Aspnet #256
It seems that when registering a service as SingletonPerKey, and the service implements IDisposable in aspnet core, it disposes per request, however instance is created only once.
Execution flow is as follows
First request > initialize service (ctor) > execute > call .Dispose()
I was able to reproduce this and I'll have some time next week to release a fix. For the next couple days you could try marking the export as externally owned .ExternallyOwned() and it will keep it from being disposed (ever).
After updating to the mentioned version 7.1.1-RC793, SingletonPerKey as my usage isn't working anymore. Basically can't get the data from .GetExtraData from either scope/context inorder to resolve the tenant
Ok I pushed a newer version and tested it with your repo. Usually the scope & disposal scope should be the same so that you don't get data from a child scope but in your case you actually do need the data from the child scope.
Thanks I retested it again, however its partially solved. In my example the IDataClientManager is not being disposed but the service implementing IHeroDataClient e.g. MockHotsHeroDataClient its still being disposed as it was (and is also SingletonPerKey).
Further more I retested the actual scenario (e.g. GQL) and it still happens that the Schema is being disposed
Activity
ipjohnson commentedon Apr 8, 2020
I agree it should dispose only at when the host is disposed. Can you email me the sample and I'll take a look at tonight or tomorrow morning.
stephenlautier commentedon Apr 8, 2020
Its available here https://github.com/sketch7/dotnet.multitenancy/tree/feature/initial-imp (this branch)
Sketch7.Multitenancy.Sample.ApiInteresting points:
[-]SingletonPerKey disposing in Aspnet issue[/-][+]SingletonPerKey disposing per request in Aspnet[/+]ipjohnson commentedon Apr 10, 2020
I was able to reproduce this and I'll have some time next week to release a fix. For the next couple days you could try marking the export as externally owned
.ExternallyOwned()and it will keep it from being disposed (ever).addressing disposal issue for #256 as well as more tests
ipjohnson commentedon Apr 13, 2020
Ok I have a fix for it, essentially the wrong disposal context was being used. I've released a new pre-release let me know how it works out for you.
stephenlautier commentedon Apr 14, 2020
Can you confirm if this one only I need to update
Grace: 7.1.1-RC793?stephenlautier commentedon Apr 14, 2020
After updating to the mentioned version
7.1.1-RC793, SingletonPerKey as my usage isn't working anymore. Basically can't get the data from.GetExtraDatafrom either scope/context inorder to resolve the tenantP.S. running the same sample also breaks
changing export scope to be request based for issue #256
ipjohnson commentedon Apr 14, 2020
Ok I pushed a newer version and tested it with your repo. Usually the scope & disposal scope should be the same so that you don't get data from a child scope but in your case you actually do need the data from the child scope.
stephenlautier commentedon Apr 14, 2020
Thanks I retested it again, however its partially solved. In my example the
IDataClientManageris not being disposed but the service implementingIHeroDataCliente.g.MockHotsHeroDataClientits still being disposed as it was (and is also SingletonPerKey).Further more I retested the actual scenario (e.g. GQL) and it still happens that the Schema is being disposed
ipjohnson commentedon Apr 17, 2020
As we’ve talked about this over email and it’s resolved I’m going to close this out. If you have any other issues let me know