Enterprise Library 5.0 ObjectBuilder is removed. Assembler Attribute and some other options are not available

Topics: Exception Handling Application Block, General discussion
Oct 23, 2012 at 7:31 AM
Edited Oct 29, 2012 at 9:45 AM

Hi all,

We are implementing Custom ExceptionHandlers..We are previously using Assembler attribute of  "Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder;" (Enterprise Library 3.1). When trying to upgrade to EL 5.0, We came to know that object builder is now deprecated and all features are added in Unity. I could not find the Assembler attribute or ConfigurationReflectionCache class in any of the unity DLLs. We are currently struck at this point. Kindly help soon.

Oct 23, 2012 at 1:32 PM

The Assembler attribute is not used in Enterprise Library 5.  See: http://entlib.codeplex.com/discussions/225608 for more information.  Also see Creating a Custom Provider for the steps on creating a custom provider.

You need to override the public virtual IEnumerable<TypeRegistration> GetRegistrations(string namePrefix) method and in that method specify how to create the object.  See this example from the Enterprise Library ReplaceHandlerData.cs:

        /// <summary>
        /// A <see cref="TypeRegistration"/> container configuration model for <see cref="ReplaceHandler"/>.
        /// </summary>
        /// <param name="namePrefix">The prefix to use when determining references to child elements.</param>
        /// <returns>A <see cref="TypeRegistration"/> for registering a <see cref="ReplaceHandler"/> in the container.</returns>
        public override IEnumerable<TypeRegistration> GetRegistrations(string namePrefix)
            IStringResolver resolver
                = new ResourceStringResolver(ExceptionMessageResourceType, ExceptionMessageResourceName, ExceptionMessage);

            yield return
                new TypeRegistration<IExceptionHandler>(
                    () => new ReplaceHandler(resolver, ReplaceExceptionType))
                        Name = BuildName(namePrefix),
                        Lifetime = TypeRegistrationLifetime.Transient

Assuming you have an IExceptionHandler then in that class use the ConfigurationElementTypeAttribute:

    public class ReplaceHandler : IExceptionHandler

Randy Levy
Enterprise Library support engineer