-
Notifications
You must be signed in to change notification settings - Fork 77
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
IServiceProvider ObjectDisposedException fix. #102
Conversation
…is restarts. BinanceHttpClient.Initializer.IsValueCreate true, so we dont recreate BinanceHttpClient, but is needed, because the old IServiceProvider (which uses in ApiRateLimiterProvider, RateLimiterProvider) already disposed
and can you create a new release after merge? |
You can revert my changes in IServiceCollectionExtension and run test BinanceHttpClientTest.ServiceProviderDisposeNoThrows @sonvister |
@tash649, could you help me to better understand your use case? I see from your test that you are disposing of and recreating a Assuming your test resembles your use case (and you are not restarting app), this is not the intended/expected use of If you are needing to dispose of and create a new |
Sorry for my English, the restart it is recreation of the WebHost (.net core). Main issue is when I doing this, lazy value of BinanceHttpClient contains ApiRateLimiter which disposed already. @sonvister I don't really understand why the check I removed is needed, because the singletone service is initialized once. I understand why you use lazy. |
can you explain why you are checking the isValueCreated value? |
from my point of view, this check is redundant |
@tash649, I understand the cause of the error. I do not understand why you are not using an application-level static From your perspective, the check is unnecessary. However, other users (seemingly a majority) did not want to use dependency injection, so the API needed to also support instantiation of Ignoring any potential race conditions, it should be fine to use this: if (BinanceHttpClient.Initializer.IsValueCreated)
BinanceHttpClient.Initializer.Value.Dispose(); |
@tash649, instead of merging this pull request, I added the modifications as mentioned in the previous comment with similar unit test cases. Let me know if these changes work for you. |
Thank you very much @sonvister |
@tash649, 0.2.0-beta7 is released. Donations (DCR, LTC, BTC, other...) appreciated 😉 |
Thank you. (not recommended usage). That's what I'm doing. I use application-scopes IServiceProvider. In my case I just can recreate this scope. Iam stopping Webhost, then I create a new one and start again. |
@tash649, I am referring to using a single instance of I may better understand your use case now, but I would still recommend restarting your application by restarting the process (instead of rebuilding the WebHost from within). Have you considered/tried Regardless, I don't mind that this library supports (the odd case of) re-initializing |
I have not had much recent experience with ASP.NET, perhaps I will experiment with this sometime.... Also, I found this: "Allow overriding the hosting service provider". Seems others have had issues with the WebHost being the DI universe. The example usage: ExternalContainerInstanceCanBeUsedForEverything. |
Error occures when app is restarts. BinanceHttpClient.Initializer.IsValueCreate is true, so we dont recreate BinanceHttpClient, but is needed, because the old IServiceProvider (which uses in ApiRateLimiterProvider, RateLimiterProvider) already disposed
.net core 2.1.1