A Really Super Light and Simple IoC Container for Windows Phone 7

I finally managed to get the Windows Phone 7 tools installed. I’m not going to vent on that anymore because I feel like I’ve done that enough already – and once they did install correctly they’ve been very pleasurable to use. I started working on an application, and old habits die hard. I like Inversion of Control, it’s a major need for me simply because I’ve forced my mind to work like that. I’ve previously worked with Unity and Windsor. Unity has grown on me a lot, and I like it. However, none of them seem to work in Windows Phone 7, or at least they weren’t designed to. So I wrote my own really super simple IoC container for Windows Phone 7. I wanted the following features, and nothing else (for now):

  1. Able to register types such that arguments of it’s constructor are resolved
  2. Able to register an interface and type such that if the interface is resolved, the component is resolved and it’s constructor arguments are resolved
  3. Assume that there is either a default constructor or a single constructor that takes parameters
  4. Everything will have a singleton lifetime.

Super simple requirements. This will be running on phone hardware, so it needs to be lightweight, too. It fits in a single class which is about 65 lines. I’ve split it into two different files using a partial class to keep the registration separate. I can imagine some additional features that other people might want, such as a transient lifestyle, use WeakReferences if you are registering a lot of things, etc.

For the source, see the Gist on GitHub.

Published Thu, Nov 25 2010 19:08 by vcsjones
Filed under: ,

Comments

# re: A Really Super Light and Simple IoC Container for Windows Phone 7

Hi,

I thought there was a gap in the WP7 container space, so I wrote MicroIoc. It's on http://microioc.codeplex.com/ - I'd love your opinion on it :)

Thursday, January 06, 2011 8:54 PM by Ian Randall

# re: A Really Super Light and Simple IoC Container for Windows Phone 7

I don't understand.  The code shown here is incomplete (no interfaces provided), and the download at github is a 'tar' that I can't figure out how to open (WinZip won't open)?

Also what is the reason for the partial class inplementation?

Thursday, January 13, 2011 8:37 PM by Nick

# MVVM Light V4 preview 3 (BL16, MIX11 edition!!) #mvvmlight

At MIX11, I am releasing a new preview of MVVM Light version 4. This new preview contains one small change

Thursday, April 14, 2011 10:08 AM by Community Blogs

Leave a Comment

(required) 
(required) 
(optional)
(required) 
If you can't read this number refresh your screen
Enter the numbers above: