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

Glenn Block

Another ALT.NET guy at Microsoft

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 Glenn Block
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

Glenn Block said:

@Patrick this is a greate idea.

# May 5, 2008 7:54 PM

Glenn Block 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

Chad Myers' Blog said:

I started typing a comment to John Teague's post about Creating a Culture of Quality , but it got

# June 7, 2008 11:37 AM

ploeh blog said:

More than a year ago, I wrote my first post on unit testing WCF services . One of my points back then

# June 26, 2008 3:24 AM

Does meridia work. said:

Meridia hospitals cleveland oh. Vestigial meridia. Meridia overnight. Meridia. Pillinc buy phentermine adipex meridia online. Meridia without prescriptions. Do meridia phentermine wo. Meridia over the counter.

# July 30, 2008 6:54 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Glenn Block

Glenn is a PM for the new Managed Extensibility Framework in .NET 4.0. Prior to Microsoft, he worked for 10 years in various startups and ISVs wearing many different hats all related to developing software. Glenn has been writing code practically since the time he learned how to ride a bicycle. When he's not writing code, he's continuously improving on ways to build better software. Glenn is a geek at heart and spends a good portion of the rest of this time spreading that geekdom through conferences, and the community through groups such as ALT.NET. When he's not working and playing with technology, he spends his time with his wife and four year old daughter either at their Seattle apartment or at one of the local coffee shops. Check out Devlicio.us!

Our Sponsors

Free Tech Publications

This Blog

Syndication

News

View Glenn Block's profile on LinkedIn

Me