Code Monkey home page Code Monkey logo

apexdi's People

Contributors

inksword avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

apexdi's Issues

Cannot get the correct Singleton service when with multiple `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:

// 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');
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.