Skip to content
Mike Larah By Mike Larah Software Engineer II

As I explained in this post, the framework provides a set of installers for registering components against interfaces in the container.

Another powerful tool in the composition framework is the ContentFactory. This provides methods for registering and getting content based on a contentType string. When getting content, if the contentType is not found in the container, it will try to fallback using substrings of contentType by progressively removing sections after a .

As an example, we might have some serializers that inherit from ISerializer.

We can create a new SerializerFactory that inherits from ContentFactory.

Then we use a custom installer to register the factory as a singleton, and also to register our default content (i.e. the serializers).

We are now able to use the SerializerFactory.GetContentFor(string contentType) method to retrieve our serializers by the name we registered them with:

  • SerializerFactory.GetContentFor("Foo") will return FooSerializer
  • SerializerFactory.GetContentFor("Foo.Bar") will return FooBarSerializer
  • SerializerFactory.GetContentFor("Foo.Bar.Baz") will fallback to contentType of "Foo.Bar" and return FooBarSerializer

In the next post I'll show you how to get set up with endjin composition framework in an MVC4 / WebAPI application.


Mike Larah

Software Engineer II

Mike Larah

Mike is a Software Engineer at endjin with almost a decade 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.