Updating the Composition Root of Each Module
Explore how to update the composition root in each module by moving initialization logic to enable modules to run independently or as part of a monolith. Understand the trade-offs between monolith and microservices architectures, and prepare your application for cloud deployment with practical strategies for maintaining flexibility in your system architecture.
We'll cover the following...
Every module uses a Startup() method to initialize itself to run with the resources that the monolith has provided. Our update will be a small one. We will be moving the code within Startup() to a new Root() function. Then, we create a call to it from Startup() and it will be as though nothing has changed:
func (m *Module) Startup(ctx context.Context, mono system.Service,) (err error) {return Root(ctx, mono)}func Root(ctx context.Context, svc system.Service,) (err error) {// ...}
This simple change will allow us to reuse the composition root code for the other method of running the module, running it as a standalone ...