Autofac on Windows Phone 7

Programming on Windows Phone 7 is still a fairly new concept, new articles are surfacing frequently about how you can architect your new WP7 apps. However not many that I have seen are suggesting that components should be resolved via an IoC container. Although there are reasons for this, it is primarily boiling down to the fact that many authors feel concessions need to be made because the code is running on a limited platform. I agree with this to an extent, however I do feel that there it is still important that we don't just outright forget about the good practices that have been brewing in the industry for a while now.

The source

The WP7 branch has been merged back to the official Autofac Project.

What works

Firstly, to gain higher confidence the Autofac tests now have a special testing harness so that they can be run in the emulator and also on a physical device.

Briefly, here are a list of the components and features that are limited or will not work.

  • Lazy - the 'Lazy' type does not exist on windows phone.
  • StronglyTypedMetaData - is also removed because the implementation uses classes from System.ComponentModel.Composition which is currently unavailable on windows phone.
  • Open generics - Support for open generics is fairly weak / not supported currently on WP7. Thus you may find situations where it is impossible for Autofac to perform the Resolve. See some of my notes here.
  • Checking constraints in open generic arguments - again, not supported, can cause failures in some complex situations.


The binaries can be added to your project straight from Nuget under Autofac.WP7.

Autofac WP7
Posted by: Brendan Kowitz
Last revised: 21 Sep 2013 12:13PM


1/26/2011 9:37:50 AM

I totally agree with you on remembering our good practices, so its nice to see some WP7/Autofac love. This should definitively be "closer" to the Autofac project. I see that you have done some changes to the original 2.3 source. What would it take to bring it up to 2.4? I would be interested in looking at how this could be built into the main Autofac repo.
1/28/2011 10:46:47 AM

To get to 2.4 I plan to just pull the changes since 2.3 into the wp7 repo. All changes so far for WP7 are using conditional build statements, and there are not a great deal. Getting this back into the main repo is definitely a goal, however we have been discussing how to get the autofac tests passing in the phone emulator; this is the real problem. The tests use dependencies (NUnit, Moq and Linq) that are currently not compatible. Please definitely forward on any suggestions.


No new comments are allowed on this post.