In the last post I introduced v2.0 of our open source, composition framework. In this post, I'm going to cover a quick example of how to get started with the basics of the endjin composition framework.
Firstly, we define an interface for some type
Then, we create a concrete type for our interface
Now we can use one the composition framework's convention based installers. For instance we could use the namespace installer, to install all types in a given namespace into the container.
The namespace installer will register types against their Default interface - where the default interface is the interface that follows the naming convention
I + [my specific name] + [service name] (e.g. the default interface for
class FooBarService : IFooService, IFooBarService is
Most of the convention-based installers will install the concrete type into the container as Transient by default, but we can explicit specify the lifestyle using
See the Installers page on the GitHub wiki for a complete list of all the installers included in the framework, and explanations of how they work.
Next step is to initialize the container within our application's start-up code. This is done using the Bootstrapper appropriate for whichever framework we are using, which will locate the installers in our assemblies and install the types they find into the container.
You can now use the static
ApplicationServiceLocator.Container for resolving your root types.
In the next post, I'll go over how to use the ContentFactory for registering content with custom names.