Customization/Extensions to Ent. Lib 3.1 do not compile in Ent. Lib 4.0

Topics: Building and extending application blocks, Exception Handling Application Block, Logging Application Block
Oct 9, 2008 at 1:41 PM

I have some customized code which acts as a wrapper around Ent. Library 3.1 Exception Handling and Logging blocks. For example I have a custom Exception handler defined and also custom trace listeners. Now everything works fine in the Enterprise library 3.1 world and I was assuming the same customization should work unchanged with Enterprise library 4.0 but that is not true! There are a bunch of changes in the Interface and the object model in 4.0. A lot of the methods exposed in 3.1 seem to be deprecated in 4.0. Now after I installed the source code for 4.0 and changed all my references to the 4.0 references in my custom wrapper, I get a bunch of compilation errors. One of them is the following,

I have a custom FormattedDatabaseTraceListener and in the tracelistener I have the custom assembler class that derives from TraceListenerAssembler. The compiler gives me an error on this line, 


Database database =(Microsoft.Practices.EnterpriseLibrary.Data.Database)context.HeadOfChain.BuildUp(context, typeof(Microsoft.Practices.EnterpriseLibrary.Data.Database), null, castedObjectConfiguration.DatabaseInstanceName);


Error 2 'Microsoft.Practices.ObjectBuilder2.IBuilderContext' does not contain a definition for 'HeadOfChain' and no extension method 'HeadOfChain' accepting a first argument of type 'Microsoft.Practices.ObjectBuilder2.IBuilderContext' could be found (are you missing a using directive or an assembly reference?) E:\Projects\LH Common\Dev_2008\ExceptionAndLoggingFramework\Dmti.Logging\Configuration\FormattedDmtiDatabaseListenerData.cs 133 78 Dmti.Logging

What does this line translate to in the 4.0 world?? 

Also, if there are a list of changes from 3.1 to 4.0 in terms of object model and how they translate will be great. Maybe there is something like that already and if someone could point to me that as well that will be greatly appreciated!

Thank You & Regards
Oct 10, 2008 at 1:17 PM

Hi Vanitha,

The issues you're facing are a result of the upgrade from ObjectBuilder v1 to ObjectBuilder v2. The equivalent to the line you pasted is:

            IBuilderContext databaseContext

                = context.CloneForNewBuild(

                    NamedTypeBuildKey.Make<Data.Database>(castedObjectConfiguration.DatabaseInstanceName), null);


            Data.Database database

                = (Data.Database)databaseContext.Strategies.ExecuteBuildUp(databaseContext);

Hope this helps,

Oct 10, 2008 at 3:08 PM
Thank you Fernando. That did help. Also I am now looking into the source code for 4.0 and it looks like I might have to do a straight comparison between the custom code that I have and the source code for 4.0 for all the files. Is there a better approach ??

Thanks again