CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Glenn Block


PrismShouldNotReferenceUnity

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.

image 

My heart skipped a beat before he ran it...

image

Any questions?

Published May 04 2008, 09:40 PM by gblock
Filed under: , ,

Comments

Ayende @ Rahien said:

Actively enforce your conventions

# May 5, 2008 3:51 AM

Chris Tavares said:

It's good to be loved.

# May 5, 2008 5:12 AM

Peter Ritchie said:

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).

# May 5, 2008 11:50 AM

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# May 5, 2008 11:53 AM

Patrick Smacchia said:

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

WARN IF Count > 0 IN SELECT ASSEMBLIES WHERE

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:

codebetter.com/.../mono-cecil-vs-system-reflection.aspx

# May 5, 2008 12:13 PM

gblock said:

@Patrick this is a greate idea.

# May 5, 2008 7:54 PM

gblock said:

@Chris

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.

# May 5, 2008 7:55 PM

Reflective Perspective - Chris Alcock » The Morning Brew #87 said:

Pingback from  Reflective Perspective - Chris Alcock  » The Morning Brew #87

# May 6, 2008 3:23 AM

Patrick Smacchia [MVP C#] said:

Recently, both Glenn Block and Ayende wrote about how to define some sort of active conventions about

# May 11, 2008 4:53 PM

Community Blogs said:

Recently, both Glenn Block and Ayende wrote about how to define some sort of active conventions about

# May 12, 2008 3:44 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About gblock

Glenn Block is the Technical Product Planner for the Client UX program at patterns & practices. As Product Planner he is responsible for driving the vision and creation of p&p client deliverables including the Web Client and Smart Client software factories. Prior to joining Microsoft, Glenn has lived in various roles being "in the trenches" with developers, including being responsible for the overall architecture and technology direction. He has worked in both large and small organizations building enterprise systems for financial services, manufacturing, and print & mail on multiple platforms including .NET and Java. His technology passions are in software frameworks, architecture and systems integration. He resides with his wife and 3 year old daughter in Seattle (his other passion). Check out Devlicio.us!

This Blog

Syndication

News

View Glenn Block's profile on LinkedIn

Me