[dba-VB] MS Patterns & Practices: Entlib 5.0 and Unity 2.0 -they made it finally - that's a real ..

Shamil Salakhetdinov shamil at smsconsulting.spb.ru
Mon Sep 13 12:09:41 CDT 2010


Hi Gustav --

I suppose this is the case when one has to find 58 minutes as this time
investment promise to bring big savings in long run.
MS made it this time - I suppose...
I was always quite a bit skeptical about what they were doing in that area
because they were doing that at the beginning as an experiment not as "dog
food to themselves" - and it's now used like that ("dog food for
themselves") there - so this is a real stuff for sure. And one can just
analyze what is done in the most advanced and useful Instrumentation and
Dependency Injection frameworks by today and compare with Entlib5 and Unity
2.0 - and you'll find MS didn't reinvent the wheel MS way creating yet
another "behemoth" - the opposite is true - they have made a lightweight
framework where many parts can be replaced by custom stuff if needed or used
as it's - out of the box etc.

What is also important is that the tuning of used Enterprise Library
Block(s) (e.g. Logging) can be done directly on deployment site without any
programming but by using special config editing tool or within VS using
similar tool/editor:

http://smsconsulting.spb.ru/test/entlib5.jpg

And one can start using Unity 2.0 and, say, Logging block almost immediately
- as in the sample code in P.S. of this message - not the best possible
sample code I could have made - it's just to show how easy is to start with
that advanced Entlib 5 and Unit 2.0 stuff:

- using code in P.S. and tuning of config file you'll get in the log (and
log can be set for MS Windows Event Log, Flat File, Database,...  in config
file):

Message: Test Message 1
Message: Test Message 2

Or

Timestamp: 13/09/2010 16:38:17
Message: Test Message 1
Category: General
Priority: -1
EventId: 1
Severity: Information
Title:
Machine: NANT
App Domain: ConsoleApplication1.exe
ProcessId: 2728
Process Name: G:\Samples\Microsoft Enterprise Library 5.0 - Hands On
Labs\CS\Logging\exercises\ex01\begin\ConsoleApplication1\bin\Debug\ConsoleAp
plication1.exe
Thread Name: 
Win32 ThreadId:3012
Extended Properties:
...

Thank you.

-- Shamil


P.S.

// set references to:
//  Microsoft.Practices.EnterpriseLibrary.Common
//  Microsoft.Practices.EnterpriseLibrary.Logging
//  Microsoft.Practices.ServiceLocation
//  Microsoft.Practices.Unity
// 
using System;
using Microsoft.Practices.EnterpriseLibrary.Logging;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.Unity;

namespace ConsoleApplication1
{
    class TestProgram
    {
        static void Main(string[] args)
        {
            try
            {
                MyResourceLocator.UC
                    .RegisterInstance(typeof(LogWriter),
                    new LogWriterFactory().Create());

                Test1.Run();
                Test2.Run(); 
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);   
            }
        }
    }
    public sealed class MyResourceLocator
    {
        private static IUnityContainer _container;
        public static IUnityContainer UC
        {
            get
            {
                if (_container == null) _container = 
                    new UnityContainer();
                return _container; 
            }
        }
    }

    public class Test1
    {
        public static void Run()
        {
            LogWriter writer = (LogWriter)MyResourceLocator.UC
                .Resolve(typeof(LogWriter));
            writer.Write("Test Message 1");
        }
    }
    public class Test2
    {
        public static void Run()
        {
            ((LogWriter)MyResourceLocator.UC
                .Resolve(typeof(LogWriter)))
                .Write("Test Message 2");
        }
    }
}

-----Original Message-----
From: dba-vb-bounces at databaseadvisors.com
[mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock
Sent: Monday, September 13, 2010 7:15 PM
To: dba-vb at databaseadvisors.com
Subject: Re: [dba-VB] MS Patterns & Practices: Entlib 5.0 and Unity 2.0
-they made it finally - that's a real ..

Hi Shamil

I'm aware of the first but not the second. For example, the validation part
of the Enterprise Library is certainly interesting, and the other parts may
be as well - it frees you from reinventing the wheel - indeed when your
"wheel" most likely would be less sophisticated than the EL wheel anyway.

But Unity? So much to learn. Why can't I have 58 minutes more per day
watching videos?

Happy Programmer Day! 

/gustav

http://databaseadvisors.com/mailman/listinfo/dba-vb
http://www.databaseadvisors.com




More information about the dba-VB mailing list