Microsoft Enterprise Library 5.0 and Unity 2.0 Migration Guide


This guide explains the opportunities open to you for migrating applications built using Enterprise Library versions 3.1, 4.0, and 4.1, and versions 1.0 and 1.1 of Unity to use version 5.0 or Enterprise Library and version 2.0 of Unity.

Because individual application scenarios and environments vary, and the way Enterprise Library and Unity are used within existing applications will differ considerably, this guide cannot guarantee success in every situation. However, it contains practical guidance that is based on knowledge gathered during the development of Enterprise Library 5.0, and through test migrations of a range of different existing applications.

Microsoft Enterprise Library 5.0 Migration Guide can be downloaded from from MSDN in PDF and XPS formats.

Last edited Apr 20, 2010 at 7:48 PM by gmelnik, version 4

Comments

sriharshakolluru Oct 23, 2012 at 5:41 AM 
It never explained what happenned to Common.Configuration.ObjectBuilder.Assembler or ConfigurationReflectionCache or IAssembler .. Please release the documentation or explain how to use them. Unity does not contain any definition for these.

gmelnik Feb 10, 2011 at 2:05 AM 
@rajasekart
Object Builder, the low-level dependency injection mechanism, has been subsumed into Unity in V5.0. You no longer need to reference the Object Builder assembly in your projects, or distribute it with your applications. Please see the release notes. Also, for faster response, consider posting your issues under Discussions.

rajasekart Dec 10, 2010 at 1:33 AM 
I am migrating enterprise library 3.1 to 5 and getting errors in the below code. It seems Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder namespace not found in Enterprise library 5.0. Please let me know if anyone know about this

using System;
using System.Collections.Generic;
using System.Text;

using System.ComponentModel;
using System.Configuration;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Logging;
using System.Diagnostics;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder;
using Microsoft.Practices.ObjectBuilder;
using Microsoft.Practices.Unity.ObjectBuilder;
using Microsoft.Practices.ServiceLocation;

using Microsoft.Practices.CompositeWeb;
using Microsoft.Practices.CompositeWeb.Web;
using Microsoft.Practices.CompositeWeb.Interfaces;

using CRDesktop.Infrastructure.LogService;


namespace CRDesktop.Infrastructure.ExceptionFramework
{
/// <summary>
/// Represents configuration for a <see cref="LoggingExceptionHandler"/>.
/// </summary>
[Assembler(typeof(CRDesktopLoggingExceptionHandlerAssembler))]
public class CRDesktopLoggingExceptionHandlerData : ExceptionHandlerData
{
private static AssemblyQualifiedTypeNameConverter typeConverter = new AssemblyQualifiedTypeNameConverter();

private const string logCategory = "logCategory";
private const string eventId = "eventId";
private const string severity = "severity";
private const string title = "title";
private const string formatterType = "formatterType";
private const string priority = "priority";

/// <summary>
/// Initializes with default values.
/// </summary>
public CRDesktopLoggingExceptionHandlerData()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="LoggingExceptionHandlerData"/> class.
/// </summary>
/// <param name="name">
/// The name of the handler.
/// </param>
/// <param name="logCategory">
/// The default log category.
/// </param>
/// <param name="eventId">
/// The default eventID.
/// </param>
/// <param name="severity">
/// The default severity.
/// </param>
/// <param name="title">
/// The default title.
/// </param>
/// <param name="formatterType">
/// The formatter type.
/// </param>
/// <param name="priority">
/// The minimum value for messages to be processed. Messages with a priority below the minimum are dropped immediately on the client.
/// </param>
public CRDesktopLoggingExceptionHandlerData(string name, string logCategory, int eventId,
TraceEventType severity, string title, Type formatterType, int priority)
:this(name, logCategory, eventId, severity, title, typeConverter.ConvertToString(formatterType), priority)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="LoggingExceptionHandlerData"/> class.
/// </summary>
/// <param name="name">
/// The name of the handler.
/// </param>
/// <param name="logCategory">
/// The default log category.
/// </param>
/// <param name="eventId">
/// The default eventID.
/// </param>
/// <param name="severity">
/// The default severity.
/// </param>
/// <param name="title">
/// The default title.
/// </param>
/// <param name="formatterTypeName">
/// The formatter fully qualified assembly type name.
/// </param>
/// <param name="priority">
/// The minimum value for messages to be processed. Messages with a priority below the minimum are dropped immediately on the client.
/// </param>
public CRDesktopLoggingExceptionHandlerData(string name, string logCategory, int eventId,
TraceEventType severity, string title, string formatterTypeName, int priority)
: base(name, typeof(CRDesktopLoggingExceptionHandler))
{
LogCategory = logCategory;
EventId = eventId;
Severity = severity;
Title = title;
FormatterTypeName = formatterTypeName;
Priority = priority;
}

/// <summary>
/// Gets or sets the default log category.
/// </summary>
[ConfigurationProperty(logCategory, IsRequired = true)]
public string LogCategory
{
get { return (string)this[logCategory]; }
set { this[logCategory] = value; }
}

/// <summary>
/// Gets or sets the default event ID.
/// </summary>
[ConfigurationProperty(eventId, IsRequired = true)]
public int EventId
{
get { return (int)this[eventId]; }
set { this[eventId] = value; }
}

/// <summary>
/// Gets or sets the default severity.
/// </summary>
[ConfigurationProperty(severity, IsRequired = true)]
public TraceEventType Severity
{
get { return (TraceEventType)this[severity]; }
set { this[severity] = value; }
}

/// <summary>
/// Gets or sets the default title.
/// </summary>
[ConfigurationProperty(title, IsRequired = true)]
public string Title
{
get { return (string)this[title]; }
set { this[title] = value; }
}

/// <summary>
/// Gets or sets the formatter type.
/// </summary>
public Type FormatterType
{
get { return (Type)typeConverter.ConvertFrom(FormatterTypeName); }
set { FormatterTypeName = typeConverter.ConvertToString(value); }
}

/// <summary>
/// Gets or sets the formatter fully qualified assembly type name.
/// </summary>
/// <value>
/// The formatter fully qualified assembly type name
/// </value>
[ConfigurationProperty(formatterType, IsRequired = true)]
public string FormatterTypeName
{
get { return (string)this[formatterType]; }
set { this[formatterType] = value; }
}

/// <summary>
/// Gets or sets the minimum value for messages to be processed. Messages with a priority
/// below the minimum are dropped immediately on the client.
/// </summary>
[ConfigurationProperty(priority, IsRequired = true)]
public int Priority
{
get { return (int)this[priority]; }
set { this[priority] = value; }
}
}

/// <summary>
/// This type supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
/// Represents the process to build a <see cref="LoggingExceptionHandler"/> described by a <see cref="LoggingExceptionHandlerData"/> configuration object.
/// </summary>
/// <remarks>This type is linked to the <see cref="LoggingExceptionHandlerData"/> type and it is used by the <see cref="ExceptionHandlerCustomFactory"/>
/// to build the specific <see cref="IExceptionHandler"/> object represented by the configuration object.
/// </remarks>
public class CRDesktopLoggingExceptionHandlerAssembler : IAssembler<IExceptionHandler, ExceptionHandlerData>
{
/// <summary>
/// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
/// Builds an <see cref="LoggingExceptionHandler"/> based on an instance of <see cref="LoggingExceptionHandlerData"/>.
/// </summary>
/// <seealso cref="ExceptionHandlerCustomFactory"/>
/// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param>
/// <param name="objectConfiguration">The configuration object that describes the object to build. Must be an instance of <see cref="LoggingExceptionHandlerData"/>.</param>
/// <param name="configurationSource">The source for configuration objects.</param>
/// <param name="reflectionCache">The cache to use retrieving reflection information.</param>
/// <returns>A fully initialized instance of <see cref="LoggingExceptionHandler"/>.</returns>
public IExceptionHandler Assemble(IBuilderContext context, ExceptionHandlerData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
{
CRDesktopLoggingExceptionHandlerData castedObjectConfiguration
= (CRDesktopLoggingExceptionHandlerData)objectConfiguration;

ILogService logService= null;
LogWriter writer = null;
try
{
WebClientApplication wc = (WebClientApplication)System.Web.HttpContext.Current.ApplicationInstance;
logService = (ILogService)wc.RootContainer.Services.Get(typeof(ILogService));
}
catch (Exception)
{
// The ILogService is not available at the point where the exception occured so
// let's go ahead and write it to the file directly so as not to loose any exception
// history in log file.
writer = (LogWriter)context.HeadOfChain.BuildUp(context, typeof(LogWriter), null, null);
}
CRDesktopLoggingExceptionHandler createdObject
= new CRDesktopLoggingExceptionHandler(
castedObjectConfiguration.LogCategory,
castedObjectConfiguration.EventId,
castedObjectConfiguration.Severity,
castedObjectConfiguration.Title,
castedObjectConfiguration.Priority,
castedObjectConfiguration.FormatterType,
logService,
writer);

return createdObject;
}
}
}

christopherlauer Oct 7, 2010 at 1:37 PM 
You guys rock! Not only does the patterns & practices team create well designed, functional and easy to use utilities you guys (and gals) create wonderful documentation! Thank you for this Microsoft Enterprise Library 5.0 and Unity 2.0 Migration Guide. It worked like a charm and saved me countless hours of work. Keep up the good stuff (and ask for a raise, tell them I said you should get one).