Daniel Hoelbling-Inzko talks about programming

Common Service Locator adapter for Pandora

Posted by Daniel Hölbling on June 4, 2009

In case you haven’t heard. Some time ago Microsoft sat with most authors of leading IoC containers and defined a common interface for Dependency Injection / Service Location. You can get all the relevant information about the Common Service Locator through reading Glenn Block, Ayende Rahien or Chris Travares and you can download it from it’s Codeplex site. There is a comprehensive API reference in their wiki too.

Ayende sums the purpose of the CSL up pretty well:

The idea is based off a post that Jeremy Miller had about a month ago, having a common, shared interface across several IoC implementation. That would allow library authors to make use of the benefits of a container without taking a dependency on a particular implementation.

The alternative for that is to each library to create its own abstraction layer. A good example of that is NServiceBus' IBuilder interface, or ASP.NET MVC's IControllerFactory. That is just annoying, especially if you are integrating more than a single such framework.

In Pandora I aimed for CSL compliance from the beginning, and the CSLAdapter class has been there for quite some time now. But since Pandora only recently got the named lookups feature I never finished it.

Until now. Today I finally implemented the CommonServiceLocatorAdapter that (for me) somehow “verifies” that Pandora supports most mandatory lookup features needed from a DI container.

On the implementation side: I first tried to implement IServiceLocator directly, until I discovered the abstract ServiceLocatorImplBase class that wraps all of the overloads and generic/nongeneric stuff, saving you a bunch of boilerplate code.

Coming up next in Pandora will be component lifestyles, forwards and then maybe DLR configuration.

comments powered by Disqus

My Photography business


dynamic css for .NET