Dependency Injection: General Information

In the code of MYOB Acumatica Framework-based applications, you can use dependency injection to encapsulate particular logic as a service, which you can then use anywhere in your application.

Applicable Scenarios

You implement dependency injection if you need to reduce tight coupling between components and make code easier to maintain, test, and extend. By separating object creation from object usage, dependency injection allows implementations to be changed without affecting dependent code.

Implementation of Dependency Injection

To implement dependency injection in your application, you need to:

  1. Define the service for dependency injection. For details, see Dependency Injection: Service Definition.
  2. Register the service, as described in Dependency Injection: Service Registration.
  3. Inject the logic in a class in your application. For more information, see Dependency Injection: Use of Dependency Injection.
Important:
  • Dependency injection in MYOB Acumatica Framework-based applications requires the use of the external Autofac library. MYOB does not guarantee the backward compatibility of this library. For details about the Autofac library, see https://autofac.readthedocs.io/en/latest/.
  • You need to use the version of the Autofac library that is provided in the Bin folder of the MYOB Acumatica instance to which you publish the customization project. You don’t need to include the file of the Autofac library in your customization project.
Attention: Dependency injection can be implemented in a project of your MYOB Acumatica extension library, which is compiled to an external DLL file. You can’t include the implementation of dependency injection in a Code item in a customization project.
Tip: For information about dependency injection in unit tests and PX.Tests.Unit.TestBase-derived classes, see Test Method: Registration of Services and Test Method: To Register a Service.