Clarification: We are not against using Unity, the Prism RI uses Unity, and we’ve been very happy with it’s implementation. We are after all one of Unity’s first internal customers. On the other hand, we want to make it easier for customers to use their IOC container of preference, which is what this post illustrates.

Friday night Oren (Ayende) and I headed downtown to Seattle at the Tap House grill, where we paired and hacked there and at my apartment into the early hours of the morning. You can see me tweeting about it below.

image  image

One of the best parts of the evening is the part I have highlighted in red, which happened after a discussion we had on how Prism does not depend on Unity. I told Oren that we had thought of automating as part of our tests to check whether or not any reference was included but that we found it unnecessary as the team was very clear on this requirement. He however disagreed and said “You should, you should” in order that we emphasize it. He then pulled open VS and wrote this test.


My heart skipped a beat before he ran it…


Any questions?

This entry was posted in Featured, misc, prism. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • MichaelFreidgeim

    Images are broken

  • gblock


    Unity is loved by the Prism team! It’s the container we’re shipping with on our RI. I think we’re one of Unity’s first customers :)

    We want to make it easier for those that prefer other containers and therefore want to remove hard dependencies in the core.

  • gblock

    @Patrick this is a greate idea.

  • Patrick Smacchia

    Wouldn’t be more easy to use a NDepend/CQL rule, in your case it would look like:

    IsDirectlyUsedBy “ASSEMBLY:Prism.Interfaces” AND // ASSEMBLY: is here to avoid conflict with namespaces
    NameLike “Unity” // Or any regex

    Also with System.Reflexion you expose yourself with plenty of problems I ran throught the past years:

  • Peter Ritchie

    Some thoughts:

    Assembly.ReflectionOnlyLoad is likely better than Assembly.Load unless the assemblies you’re checking are also references in your test project. You might get false test failures if all the dependant assemblies aren’t in the same directory.

    If they are references in your test project (which means all their references are also copied to the same directory) then I’d recommend using a type from each of the assemblies instead of a “magic” string.

    For example:
    var asms = new Assembly[]
    {typeof (Prism.Interfaces.IRegionManagerService).Assembly,
    typeof (Prism.RegionManager).Assembly};

    ..this way you get compile-time errors should the namespace names change (which would be runtime errors using strings).

  • Chris Tavares

    It’s good to be loved.