Compose

This article is a work in progress!

If you have been given this url, I hope you can provide some early feedback for an article that is work in progress. I may also link to an incomplete page (to help me not forget), so apologies if you've arrived here by accident.

This draft was published: April 16, 2015

Check back soon for the complete article!

This article is outdated!

Unfortunately, an update to this article is not available. If you would like this article to be updated, drop a comment below or use one of the links at the bottoms of this page to contact me.

This draft was published: April 16, 2015

Posted with : Compose

In a previous post we touched on factors that need to be considered when structuring your applications. In this article we’ll go into more detail, take a look at the Compose framework and how composition can be made easier. I’ll explain some of the more advanced concepts involved when taking a look at IoC, not just DI, and we’ll introduce some cool features Compose can provide for you.

What’s Compose?

Compose is a lightweight NuGet package designed to extend or replace your existing choice of Dependency Injection container in order to assist you in creating clean, isolated components that correctly invert dependency flow.

The API is based upon the ASP.Net MVC OWIN startup patterns many are already familiar with, and are very simple to learn if not. We also provide additional packages such as Compose.ServiceExtension which will create the necessary files and boilerplate code required to get you started.

It’s just a DI Container?

No. There are enough fantastic DI containers out there; Ninject, Autofac, Unity to name a few. Compose does provide Dependency Injection, but it does so by wrapping Microsoft.Framework.DependencyInjection; a clean open source library being developed as part of the work on vNext.

Compose extends the new DI Infrastructure, allowing your services to be written with nothing more than references to System namespaces, only involving Compose in your composition root or application host to bring things together cleanly. You can of course bring your services together yourself without any reliance on Compose, but you’d be missing out on some great features!

Transitioning

Have you ever had a cloud or third party service go down that your software relied upon? Have you ever wanted to component or integration test the entirety of your application or service but needed to switch out just a couple interface implementations to feed in test data? Have you ever wanted to switch your services at runtime?

A key feature of Compose is the ability to transition your services whilst your application is running. More importantly, it allows you to do this without making any changes to your code. Any service registered through the Microsoft dependency injection framework can be marked as Transitionable during registeration using one of the helper extensions provided. From there on, you can simple call app.Transition<ISomeService, DifferentImplementationOfSomeService>().

Anywhere in your application that is already consuming ISomeService will start using the new implementation.

Written on April 16, 2015