Introducing endjin composition framework 2.0 : Part 4 - ASP.NET MVC/WebAPI
To use endjin composition framework with an ASP.NET MVC 4/WebAPI application, firstly pull in the Endjin.Core.Composition.Web package from NuGet.
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.