Assembling via Plain Code

Learn how to assemble your application via plain code.

Implementing the configuration component

There are several ways to implement a configuration component responsible for assembling the application. If we’re building an application without the support of a dependency injection framework, we can create such a component with plain code:

Press + to interact
package copyeditor.configuration;
class Application {
public static void main(String[] args) {
AccountRepository accountRepository = new AccountRepository();
ActivityRepository activityRepository = new ActivityRepository();
AccountPersistenceAdapter accountPersistenceAdapter =
new AccountPersistenceAdapter(accountRepository, activityRepository);
SendMoneyUseCase sendMoneyUseCase =
new SendMoneyUseService(
accountPersistenceAdapter, // LoadAccountPort
accountPersistenceAdapter); // UpdateAccountStatePort
SendMoneyController sendMoneyController =
new SendMoneyController(sendMoneyUseCase);
startProcessingWebRequests(sendMoneyController);
}
}

This code snippet is a simplified example of what such a configuration component might look like. In Java, an application is started from the main method. Within this method, we instantiate all the classes we need, from web controller to persistence ...