apexfarm / apexdi Goto Github PK
View Code? Open in Web Editor NEWA dependency injection framework ported from .Net Core for Apex.
License: Apache License 2.0
A dependency injection framework ported from .Net Core for Apex.
License: Apache License 2.0
It would be great if we could configure these module services in metadata
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:
// use module to resolve services
DI.Module defaultModule = DI.getModule(DefaultServiceModule.class);
IAccountService accountServiceInstance = (IAccountService) defaultModule.getService(IAccountService.class);
List<Account> defaultResult = accountServiceInstance.getAccounts();
system.debug('Default result');
system.debug(defaultResult);
DI.Module mockModule = DI.getModule(MockServiceModule.class);
IAccountService mockAccountServiceInstance = (IAccountService) mockModule.getService(IAccountService.class);
List<Account> mockResult = mockAccountServiceInstance.getAccounts();
system.debug('mock result');
system.debug(mockResult);
I get the exact same result for defaultResult
and mockResult
13:18:54:080 USER_DEBUG [17]|DEBUG|(Account:{Id=001Dn00000GY6PSIA1, Name=Sample Account for Entitlements}, Account:{Id=001Dn00000GgTgHIAV, Name=Edge Communications}, Account:{Id=001Dn00000GgTgIIAV, Name=Burlington Textiles Corp of America}, Account:{Id=001Dn00000GgTgJIAV, Name=Pyramid Construction Inc.}, Account:{Id=001Dn00000GgTgKIAV, Name=Dickenson plc}, Account:{Id=001Dn00000GgTgLIAV, Name=Grand Hotels & Resorts Ltd}, Account:{Id=001Dn00000GgTgMIAV, Name=United Oil & Gas Corp.}, Account:{Id=001Dn00000GgTgNIAV, Name=Expr
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.
13:17:36:072 USER_DEBUG [17]|DEBUG|(Account:{Name=qaa}, Account:{Name=qab}, Account:{Name=qac})
Here are my service implementations
public with sharing class AccountService implements IAccountService {
public List<Account> getAccounts() {
return [
SELECT Id, Name
FROM Account
];
}
}
public with sharing class MockAccountService implements IAccountService {
public List<Account> getAccounts() {
List<Account> accounts = new List<Account> {
new Account(Name='qaa'),
new Account(Name='qab'),
new Account(Name='qac')
};
return accounts;
}
}
public with sharing class DefaultServiceModule extends DI.Module {
public override void configure(DI.ServiceCollection services) {
services.addSingleton('IAccountService', 'AccountService');
}
}
public with sharing class MockServiceModule extends DI.Module {
public override void configure(DI.ServiceCollection services) {
services.addSingleton('IAccountService', 'MockAccountService');
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.