Following the steps from the previous posts, you can set up your interfaces, concrete types and installers. No further initialization is required though – the package includes extensions for configuring and initializing the container, and also an installer for your MVC and WebAPI controllers.
The installer looks for all MVC and WebAPI controllers in the solution and registers them into the container. The configuration initializes the container and sets it to be used by the dependency resolver for MVC and WebAPI.
So long as the composition web package is referenced, this configuration is all done automatically on application startup using WebActivator.
This now allows you to use interfaces as your controllers’ constructor parameters.
As long as concrete types for these interfaces have been registered in the container, the dependencies will be resolved whenever a request is made against a controller.
In the next post, I will be looking at what happens if you haven’t registered all dependencies, and how to debug the container.
Mike is a Software Engineer at endjin with 7 years of experience in solving business problems with technology. He has worked on a wide range of projects for clients across industries such as financial services, recruitment, and retail, with a strong focus on Azure technologies.