Wednesday, February 6, 2013

IOC Container

My objective here was to create a lightweight container using some of the newer .NET classes available. Requirements included thread safety and lazy loading.

This is more an implementation of the service locator pattern and definitely not a fully kitted IOC container as the name suggests. For someone who requires simple service registration and location from multiple threads with the added benefit of lazy loading this may be of some use.

Example Usage

Lets say you have an application consisting of a core project that contains code that you intend to reuse (for instance a portable class library) and a platform specific project that contains your UI. The UI project would register the Rope as the IPullable implementation (typically at startup). Now your core code can locate an implementation of IPullable whenever it needs it. When you port your project to another platform you can register a different implementation of IPullable (ElasticBand for example). Your core code remains unchanged and is non the wiser that its now pulling an elastic band instead to a rope.

No comments: