I would like to thank all who attended WIN406 – Dependency Injection with Enterprise Library 4.1. I hope your time in the session was worth the investment.
If I’ve been successful, you already downloaded Unity and can’t wait to use it on your current project, right?! :) For me it has been a wonderful experience to have the opportunity to talk to a so distinctive audience, and see a growing interest on Enterprise Library and Dependency Injection in general. It was really nice to see that Dependency Injection is becoming popular and popular each day!
For those who attended the session, demos and slide decks are available in my skydrive. You can download a zip file with all files.
If you want to run the demos, I would recommend you first read the demo script.
Here are also some quick and useful resources about Unity and DI in general, so you can start today:
1. Download Enterprise Library and related resources: http://msdn.microsoft.com/entlib
2. Join the Enterprise Library and Unity communities: http://codeplex.com/entlib and http://codeplex.com/unity
3. Navigate Unity Documentation http://msdn.microsoft.com/unity
4. Browse Microsoft patterns & practices catalog http://msdn.microsoft.com/practices
5. Read more about Dependency Injection Design Pattern http://martinfowler.com/articles/injection.html
[UPDATE 2009-02-25] – Slide deck is also available @ Slideshare
Following my last post around Unity and PIAB, and as already mentioned, PIAB policies have to be explicitly applied to a Unity Container.
But what about if you want to apply always the PIAB policies to your container? Easy, apply an extension that does that for you:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Configuration;
namespace MyExtensions
{
public class PolicyInjectionInterceptionExtension: Microsoft.Practices.Unity.InterceptionExtension.Interception
{
protected override void Initialize()
{
base.Initialize();
// Get the PIAB config out of entlib config
var configSource = ConfigurationSourceFactory.Create();
var section = (PolicyInjectionSettings)configSource.GetSection(PolicyInjectionSettings.SectionName);
// Apply PIAB settings, if any, to the container
if (section != null)
{
section.ConfigureContainer(this.Container, configSource);
}
}
}
}
So, instead of adding the standard Microsoft.Practices.Unity.InterceptionExtension.Interception extension, you can add MyExtensions.PolicyInjectionInterceptionExtension which auto configures the container for you.
Pretty easy, right?
Here’s a common question that normally arises when you start to use the new Unity 1.2 interception with PIAB.
Common Facts:
- You are using Unity 1.2
- You added the new Microsoft.Practices.Unity.InterceptionExtension.Interception to Unity
- You configured some policies in PIAB
- ex: Cache for some namespace
Problem:
- The Policies don’t get applied and PIAB call handlers don’t get fired
Cause and Resolution:
Because you didn’t applied the policies to the container, and that has to be explicit.
And how to it? here’s a simple example:
// Get the PIAB config out of entlib config
var configSource = ConfigurationSourceFactory.Create();
var section = (PolicyInjectionSettings)configSource.GetSection(PolicyInjectionSettings.SectionName);
// Apply PIAB settings, if any, to the container
if (section != null)
{
section.ConfigureContainer(container, configSource);
}
So, we have to get the configuration section, and apply it to the current container. To do so, the PolicyInjectionSettings now exposes a method “ConfigureContainer” which accepts the container to configure.
Other things to be aware
Also be aware that Unity 1.2 has refactored some classes that you might be using in the past if you were integrating Unity and PIAB:
- ICallHandler is no longer a PIAB interface, it is a Unity one. PIAB handlers were refactored to implement this one;
- TransparentProxyInterceptor is now on Unity (Microsoft.Practices.Unity.Interception). You also have more interception alternatives like InterfaceInterceptor and VirtualMethodInterceptor
Next post I’ll show how to write a Unity Extension to do this container configuration.
The P&P team just release a bunch of changes on EntLib 4 and Unity. Finally, PIAB is now integrated with Unity! Check out at:
Enterprise Library 4.1 - October 2008
Unity Application Block 1.2 - October 2008
Soon, I’ll try to post some impressions about this Unity release…
Sergey Solyanik left Google and is back to Microsoft. His post on the subject is just... hum.. pragmatic! Here are my favorite parts of the post: (bold format is my responsibility)
(...) "First, I love multiple aspects of the software development process. I like engineering, but I love the business aspects no less. I can't write code for the sake of the technology alone - I need to know that the code is useful for others, and the only way to measure the usefulness is by the amount of money that the people are willing to part with to have access to my work.
Sorry open source fanatics, your world is not for me! "(...)
(...)"On the other hand, I was using Google software - a lot of it - in the last year, and slick as it is, there's just too much of it that is regularly broken. It seems like every week 10% of all the features are broken in one or the other browser. And it's a different 10% every week - the old bugs are getting fixed, the new ones introduced. This across Blogger, Gmail, Google Docs, Maps, and more.
This is probably fine for free software, but I always laugh when people tell me that Google Docs is viable competition to Microsoft Office. If it is, that is only true for the occasional users who would not buy Office anyway. Google as an organization is not geared - culturally - to delivering enterprise class reliability to its user applications.
The culture part is very important here - you can spend more time fixing bugs, you can introduce processes to improve things, but it is very, very hard to change the culture. And the culture at Google values "coolness" tremendously, and the quality of service not as much. At least in the places where I worked" (...)
And with that said, we can continue to run business as usual. Back to work!
Unity is out. Check out the official release page at msdn.
I'm testing the final bits and in the next few days I'll post my thoughts about it... stay tuned!
For those who attended DEV09 and asked me the video source:
Life At Microsoft - The Truth Revealed
And for those who didn't understand why the video at the beginning of the session.. well.. it was just a teaser so I could get the audience's attention! :)
According to Grigori, the RTM version of Unity has been postponed to April 7, rather than March 15 (Well.. i guess everybody was already noticing that there wasn't any release at March 15, right?)
Meanwhile, the last weekly drop is still the March 12 one.
WOW
Now we're talking!
It's public!
Unity 1.0 RTM: 15th March (Next day to Portuguese Techdays Unity Demo: http://www.techdays.pt/session/2008/dev09.aspx)
EntLib 4 CTP: 15th March (Application blocks integration with Unity still not provided, but Object Builder 2.0 will be available)
EntLib 4 RTM: somewhere in mid-end April (including Application Blocks integration with Unity)
Stay tuned!
Finally, the so expected EntLib Dependency Injection implementation is out.
Dependency Injection is, IMHO, the most important design pattern on extensible software design. But unfortunately, Enterprise Library previously lacked the support of a lightweight Dependency Container, even if Object Builder was trying to provide this. My view is that OB was to low-level for day-to-day use.
Finally, the Unity Team provided a lightweight container for EntLib and assembled a couple of contributions to OB (and I think some community opinions)
Can't wait to post details on my test-drive. I also expect to be delivering a community session on Unity on the next weeks.. so keep tuned for more news!
Something I normally get annoyed when reviewing others code is when I have to scroll horizontally. Even when activating "Wrap", code doesn't look "sharp" and clear.
A not well known feature of Visual Studio (2002/3/5/8) is the ability to add a Guide Line to the text editor, which would show a visible line indicating a specific column. This feature of Visual Studio lets you display a vertical line at the column of your choosing to help visually see when a line is getting too long. This helps you to define a maximum acceptable column, where code should have a line break to look clear and sharp on all monitor resolutions.
Please beware that registry manipulation is needed, so DO IT AT YOUR OWN RISK:
Open a command prompt and run the following command:
REG ADD "HKCU\Software\Microsoft\VisualStudio\[Version]\Text Editor" /v Guides /d "RGB([R],[G],[B]) [COL1], [COL2]"
You should replace:
[Version]- the Visual Studio Version (Please note: 2005 = 8.0 ; 2008 = 9.0)
[R] = RGB Red value (0-255) of the line
[G] = RGB Green value (0-255) of the line
[B] = RGB Blue value (0-255) of the line
[COL1] [COL2] = The column number where to show the line. You can have at most 13 lines.
As an example, you can run the following command:
REG ADD "HKCU\Software\Microsoft\VisualStudio\8.0\Text Editor" /v Guides /d "RGB(128,0,0) 80, 120
Which would add two columns (column 80 and column 120).
Nice, no??