Пример #1
0
        /// <summary>
        /// Override of <see cref="IBuilderStrategy.BuildUp"/>. Creates the requested object using the custom factory associated to type <paramref name="t"/>.
        /// </summary>
        /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param>
        /// <param name="t">The type to build.</param>
        /// <param name="existing">The existing object. Should be <see langword="null"/>.</param>
        /// <param name="id">The ID of the object to be created.</param>
        /// <returns>The created object.</returns>
        /// <exception cref="InvalidOperationException"> when the requested type does not have the
        /// required <see cref="CustomFactoryAttribute">CustomFactory</see> attribute.</exception>
        /// <exception cref="System.Configuration.ConfigurationErrorsException"> when the configuration for the requested ID is not present or is
        /// invalid in the configuration source.</exception>
        public override object BuildUp(IBuilderContext context, Type t, object existing, string id)
        {
            string newId = id;

            IConfigurationSource         configurationSource = GetConfigurationSource(context);
            ConfigurationReflectionCache reflectionCache     = GetReflectionCache(context);

            ICustomFactory factory = GetCustomFactory(t, reflectionCache);

            if (factory != null)
            {
                existing = factory.CreateObject(context, newId, configurationSource, reflectionCache);
            }
            else
            {
                throw new InvalidOperationException(
                          string.Format(
                              Resources.Culture,
                              Resources.ExceptionCustomFactoryAttributeNotFound,
                              t.FullName,
                              id));
            }

            return(base.BuildUp(context, t, existing, newId));
        }
Пример #2
0
        public override void PreBuildUp(IBuilderContext context)
        {
            base.PreBuildUp(context);
            NamedTypeBuildKey key = (NamedTypeBuildKey)context.BuildKey;

            context.Existing = factory.CreateObject(context, key.Name, configurationSource, reflectionCache);
        }
Пример #3
0
        public override void PreBuildUp(IBuilderContext context)
        {
            base.PreBuildUp(context);
            IConfigurationSource         configurationSource = GetConfigurationSource(context);
            ConfigurationReflectionCache reflectionCache     = GetReflectionCache(context);
            NamedTypeBuildKey            key = (NamedTypeBuildKey)context.BuildKey;
            string         id      = key.Name;
            Type           t       = key.Type;
            ICustomFactory factory = GetCustomFactory(t, reflectionCache);

            if (factory != null)
            {
                context.Existing = factory.CreateObject(context, id, configurationSource, reflectionCache);
            }
            else
            {
                throw new InvalidOperationException(
                          string.Format(
                              Resources.Culture,
                              Resources.ExceptionCustomFactoryAttributeNotFound,
                              t.FullName,
                              id));
            }
        }
 public override object BuildUp(IBuilderContext context, Type typeToBuild, object existing, string idToBuild)
 {
     existing = factory.CreateObject(context, idToBuild, configurationSource, reflectionCache);
     return(base.BuildUp(context, typeToBuild, existing, idToBuild));
 }