Tuesday, March 03, 2009

IoC framework for the Compact Framework

Andy Wigley mentioned the other day the p&p team has released a series of blocks for the Compact Framework including a dependency injection framework called ContainerModel. So I decided to have a look.

You can get the code from codeplex here: http://www.codeplex.com/Mobile

It is based on the MCSF but for .NET CF 3.5.

I have had a look at the IoC framework and it is pretty good but would be even better if it had support for configuration files (XML). So currently you have to code something like this:
builder
.Register<IEditCustomersView>(
c => new EditCustomersView())
.InitializedBy(
(c, v) => v.Presenter = c.Resolve<EditCustomersPresenter>());
Then you can code this:
var view = ApplicationRoot.Container.Resolve<IEditCustomersView>();
This is a first cut so maybe we will see support for configuration files in the future. If I get time I'll add support for it.

It's quite cool as you can pass in an Action delegate at the time of register to instantiate the class.

3 comments:

Anonymous said...

Hy Simon
Ctacke just made a blog post about IoC too. See:

http://blog.opennetcf.com/ctacke/PermaLink,guid,f2ec9e37-2772-4f32-ae25-11133be4b7a3.aspx

and the interesting proposition from Filip:

http://code.google.com/p/compactcontainer/

Have fun
Daniel

Simon Hart said...

Thanks for that Daniel!.

Cheers,
Simon

Anonymous said...

If factg we now have our framework up in CodePlex too:

http://ioc.codeplex.com