A while ago I had blogged about Service Composition using ServiceStack and MEF. With ServiceStack no longer free, I figured I’d try the same thing using ASP.NET Web Api from Big Mike. The result was…not as good.
To make it work, I had to rely heavily on Autofac and their Web Api Integration packages.
First I defined the IComposableApiMetadata interface which is to be implemented by my clients. It’s 2 methods are pretty simple: one takes a ContainerBuilder to allow them to inject anything extra as per their needs, while the other returns the specific Assembly from which the ApiControllers would be loaded.
Here’s an example of what it would look like
With that done, all that should be left is calling it from the Application Start (i.e. Global.asax) right?
Sadly, this isn’t enough. I had to actually reference the client dlls in my ASP.NET MVC project, which somewhat defeats the purpose of using such a Composer. Sure I could have a process automatically update the csproj with the adequate references but that feels silly.
I am sure there is a better way and once I find it I will make sure to blog about it. Until then I hope the hour or so I spent on this will help one of you guys out there.