Endjin - Home

Introducing endjin composition framework 2.0 : Part 3 – Using the content factory

by Mike Larah

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.

@MikeLarah

About the author

Mike is a Software Engineer at endjin with 4 years experience in solving technology problems for clients. He is a certified Microsoft Cloud Platform developer, and has experience building solutions utilising much of the Azure ecosystem.