Generic dependency injection (DI) library with support for injecting Apex, Visualforce, Lightning, and Flows at runtime.
- General overview of the library features, configuration and use of Injectors (blog)
- Using the library to aid with Test Driven Development in Apex (blog)
- Dependency Injection, Flows, and Force DI (blog)
- Dependency Injection, Flows, and Force DI (webinar)
- Understanding the Value of Dependency Injection in the Lightning Platform (DF18 session)
The "core" framework is found in this project. This includes the following:
| Folder | Description |
|---|---|
| force-di | Core library, contains Injector Apex API and <c:di_injector> VF and Lightning Components Note: this contains an auto-launched flow called HelloWorld required for the unit tests to pass. If you do not want this flow to be deployed to your org, remove it before deploying; however, unit test coverage will suffer |
The "samples" of how to use the framework can be found in the Force-DI Samples project.
| Folder | Description |
|---|---|
| force-app-1 | Sample application using the API and Components to inject Apex, VF and Lightning at runtime |
| force-app-2 | Sample package providing impls for various bindings above |
| force-app-3 | Sample package providing impls for various bindings above |
| force-di-trigger-demo | Sample basic trigger framework leveraging the API |
Some of these blogs and videos are not necessarily Salesforce-specific but give good insights on use cases and purpose behind this design pattern.
- Dependency Injection Overview by Anthony Ferrara
- Advanced Apex Design Patterns by Andy Fawcett
- Writing True Unit Tests Using Dependency Injection and Mocking by Alex Tennant
- Injection Design Pattern by Martin Fowler
- Dependency Injection is not the same as Dependency Inversion by Derick Bailey
- Dependency Injection by Thorben Janssen
The upstream repository uses force-di, while this fork has renamed it to force-app. To sync with upstream updates:
- Fetch changes from the upstream
masterbranch:git fetch upstream master git merge upstream/master
- If
force-diis reintroduced, rename it directly toforce-app:This ensures that all workflows relying on the force-app directory continue to function seamlessly.mv force-di force-app
