-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Turn "More than twenty 'IServiceProvider'..." warning to error by default #10236
Comments
Marking for re-triage. Our tests are perhaps the one place where having more than twenty internal service providers is expected, since we test all the uncommon situations that require new service providers. We need to have a plan for our tests before we make a change like this. |
Triage: Try not using the internal cache in our tests... |
Issue #10236 Most of the changes here are two our tests where we use the internal service provider both as a convenience and to test specific behavior around the caching. The tests have been either: * Updated to use an external service provider explicitly * Updated to make use of a new option `ServiceProviderCachingEnabled`, which is on by default, but can be switched off to still use the internal service provider, but not to cache it. * Left untouched where the behavior being tested depends on service provider caching. This means our tests will not hit the error. We have a lot of testing of the general warning-as-error mechanism. Tested the new default throw here manually.
Issue #10236 Most of the changes here are two our tests where we use the internal service provider both as a convenience and to test specific behavior around the caching. The tests have been either: * Updated to use an external service provider explicitly * Updated to make use of a new option `ServiceProviderCachingEnabled`, which is on by default, but can be switched off to still use the internal service provider, but not to cache it. * Left untouched where the behavior being tested depends on service provider caching. This means our tests will not hit the error. We have a lot of testing of the general warning-as-error mechanism. Tested the new default throw here manually.
Issue #10236 Most of the changes here are two our tests where we use the internal service provider both as a convenience and to test specific behavior around the caching. The tests have been either: * Updated to use an external service provider explicitly * Updated to make use of a new option `ServiceProviderCachingEnabled`, which is on by default, but can be switched off to still use the internal service provider, but not to cache it. * Left untouched where the behavior being tested depends on service provider caching. This means our tests will not hit the error. We have a lot of testing of the general warning-as-error mechanism. Tested the new default throw here manually.
Further food for thought on this one. The Identity tests failed and the root cause is interesting because it doesn't directly involve calling |
@ajcvickers do we keep track of the application service provider? Would it be possible to throw only when too many internal service providers have been created for the same application service provider? |
@divega Yeah, it would be. However, I'm not sure that's the right thing to do, because the case, as hit by the Identity tests, is pathological. Consider, each test creates and throws away an app service provider, but each time it does this it adds to the collection of internal service providers, which grows without bounds. So, it would be "really great"(TM) if we could find some way to prevent this. I've been trying to figure out if we can somehow know that the root of the app service provider has been disposed, and use that to flush the entity from our cache. |
@ajcvickers I think I understand. I believe the detail that I was missing is precisely that the collection of internal service providers isn't really rooted on the application service provider. |
@ajcvickers could we register a disposable service to keep track of the lifetime of the container? |
@divega That's along the lines I was thinking. Problem is, the root |
Maybe that could be considered a bug in the tests 😄 |
@divega I thought about that too, but I don't think it really holds. |
@ajcvickers FWIW, I believe during the triage this discussion I was confused about what you were proposing. Now I think you are saying make logger factory scoped to the DbContext and stop taking an external memory cache. Is this correct? |
@divega Yes. |
Since the application is almost certainly doing something wrong. Note this is a breaking changes and so probably can't happen until 3.0.
The text was updated successfully, but these errors were encountered: