-
Notifications
You must be signed in to change notification settings - Fork 4
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
Cannot get the correct Singleton service when with multiple DI.getModule()
#1
Comments
@valorad - Thanks a lot for the feedback and a very clear issue description. Singletons are registered in a global context, once it is initialized for The following features are not supported for singleton, and here are the reasons:
In your case, it will work if the public with sharing class MockServiceModule extends DI.Module {
public override void configure(DI.ServiceCollection services) {
services.addScoped('IAccountService', 'MockAccountService'); // use addScoped()
}
} If you have new thoughts, please just let me know. And sorry to respond you 4 days late, I am busy at a new library these days. It is published now, I think it is the best SOQL query builder you can ever find in github, wish you can also have a try https://github.com/apexfarm/ApexQuery. |
I have just added a new section 1.2 Singleton Lifetime Caveat, to explain the singleton mechanism behind and how to mitigate the issue. |
@inksword Got it. Thanks for your thorough explanation! |
DI.getModule()
DI.getModule()
When I try to get two modules with the same service interface in the same context, the latter service is not retrieved correctly.
For example, when I run this in Dev console:
I get the exact same result for
defaultResult
andmockResult
While the expected result should be different.
However, when I comment out all the code for
defaultResult
, then this time the mockResult is as expected.Here are my service implementations
The text was updated successfully, but these errors were encountered: