Andy in the Cloud

From BBC Basic to Force.com and beyond…

3 thoughts on “Test Driven Development, Mocking and Force DI

  1. Where does the module class get instantiated in the basic scenario of an apex controller referencing/instantiating one or more service classes?

    public with sharing class MyController {
    private MyFirstService firstService;
    private MySecondService secondService;

    public MyController() {
    firstService = (MyFirstService) di_Injector.Org.getInstance(MyFirstService.class);

    secondService = (MySecondService) di_Injector.Org.getInstance(MySecondService.class);
    }
    }

    public class MyServicesConfiguration extends di_Module {

    public override void configure() {

    // Configure binding
    bind(MyFirstService.class).to(MyFirstService.class);
    bind(MySecondService.class).to(MySecondService.class);
    }
    }

    • The bootstrapping code that executes when the injector is first references uses the Custom Metadata Bindings to look for Modules that have been registered with it. So basically register your module with the Binding Custom Metadata type and you should be good! 🙂

  2. Pingback: Test Driven Development, Mocking and Force DI — Andy in the Cloud – SutoCom Solutions

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s