/// <summary>
 /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
 /// Returns a new instance of a concrete subtype of <typeparamref name="TObject"/>, described by the matching configuration object
 /// of a concrete subtype of <typeparamref name="TConfiguration"/> found in the <paramref name="configurationSource"/> under
 /// the name <paramref name="name"/>.
 /// </summary>
 /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param>
 /// <param name="name">The name of the instance to build, or null.</param>
 /// <param name="configurationSource">The source for configuration objects.</param>
 /// <param name="reflectionCache">The cache to use retrieving reflection information.</param>
 /// <returns>A new instance of the appropriate subtype of <typeparamref name="Tobject"/>.</returns>
 /// <exception cref="ConfigurationErrorsException">when the configuration is invalid or <paramref name="name"/> cannot be found.</exception>
 public object CreateObject(IBuilderContext context, string name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
 {
     return(Create(context, name, configurationSource, reflectionCache));
 }
예제 #2
0
        /// <summary>
        /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
        /// Builds a custom provider for type <typeparamref name="TObject"/> based on an instance of <typeparamref name="TConcreteConfiguration"/>.
        /// </summary>
        /// <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 <typeparamref name="TConcreteConfiguration"/>.</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 custom provider for type <typeparamref name="TObject"/>.</returns>
        public TObject Assemble(IBuilderContext context, TConfiguration objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
        {
            TConcreteConfiguration castedObjectConfiguration = (TConcreteConfiguration)objectConfiguration;

            TObject provider
                = (TObject)Activator.CreateInstance(objectConfiguration.Type, castedObjectConfiguration.Attributes);

            return(provider);
        }
예제 #3
0
        /// <summary>
        /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
        /// Returns a new instance of a concrete subtype of <typeparamref name="TObject"/>, described by the matching configuration object
        /// of a concrete subtype of <typeparamref name="TConfiguration"/> in <paramref name="objectConfiguration"/>.
        /// </summary>
        /// <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.</param>
        /// <param name="configurationSource">The source for configuration objects.</param>
        /// <param name="reflectionCache">The cache to use retrieving reflection information.</param>
        /// <returns>A new instance of the appropriate subtype of <typeparamref name="Tobject"/>.</returns>
        public virtual TObject Create(IBuilderContext context, TConfiguration objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
        {
            IAssembler <TObject, TConfiguration> assembler = GetAssembler(objectConfiguration);
            TObject createdObject = assembler.Assemble(context, objectConfiguration, configurationSource, reflectionCache);

            return(createdObject);
        }
        /// <summary>
        /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
        /// Returns a new instance of a concrete subtype of <typeparamref name="TObject"/>, described by the matching configuration object
        /// of a concrete subtype of <typeparamref name="TConfiguration"/> found in the <paramref name="configurationSource"/> under
        /// the name <paramref name="name"/>.
        /// </summary>
        /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param>
        /// <param name="name">The name of the instance to build, or null.</param>
        /// <param name="configurationSource">The source for configuration objects.</param>
        /// <param name="reflectionCache">The cache to use retrieving reflection information.</param>
        /// <returns>A new instance of the appropriate subtype of <typeparamref name="Tobject"/>.</returns>
        /// <exception cref="ConfigurationErrorsException">when the configuration is invalid or <paramref name="name"/> cannot be found.</exception>
        public TObject Create(IBuilderContext context, string name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException(Resources.ExceptionStringNullOrEmpty, "name");
            }

            TConfiguration objectConfiguration = GetConfiguration(name, configurationSource);

            if (objectConfiguration == null)
            {
                throw new ConfigurationErrorsException(
                          string.Format(
                              Resources.Culture,
                              Resources.ExceptionNamedConfigurationNotFound,
                              name,
                              GetType().FullName));
            }

            TObject createdObject = Create(context, objectConfiguration, configurationSource, reflectionCache);

            return(createdObject);
        }
예제 #5
0
        public IInstrumentationAttacher CreateBinder(object createdObject, object[] constructorArgs, ConfigurationReflectionCache reflectionCache)
        {
            InstrumentationListenerAttribute listenerAttribute = GetInstrumentationListenerAttribute(createdObject, reflectionCache);

            if (listenerAttribute == null)
            {
                return(new NoBindingInstrumentationAttacher());
            }

            Type listenerType       = listenerAttribute.ListenerType;
            Type listenerBinderType = listenerAttribute.ListenerBinderType;

            if (listenerBinderType == null)
            {
                return(new ReflectionInstrumentationAttacher(createdObject, listenerType, constructorArgs));
            }
            return(new ExplicitInstrumentationAttacher(createdObject, listenerType, constructorArgs, listenerBinderType));
        }
예제 #6
0
        private InstrumentationListenerAttribute GetInstrumentationListenerAttribute(object createdObject, ConfigurationReflectionCache reflectionCache)
        {
            Type createdObjectType = createdObject.GetType();
            InstrumentationListenerAttribute listenerAttribute
                = reflectionCache.GetCustomAttribute <InstrumentationListenerAttribute>(createdObjectType, true);

            return(listenerAttribute);
        }
예제 #7
0
 /// <summary>
 /// Builds an instance of the subtype of <typeparamref name="TObject"/> type the receiver knows how to build by
 /// invoking the default constructor on the type specified by the configuration object.
 /// </summary>
 /// <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.</param>
 /// <param name="configurationSource">The source for configuration objects.</param>
 /// <param name="reflectionCache">The cache to use retrieving reflection information.</param>
 /// <returns>A new instance of the <typeparamref name="TObject"/> subtype.</returns>
 public TObject Assemble(IBuilderContext context, TConfiguration objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
 {
     return((TObject)Activator.CreateInstance(objectConfiguration.Type));
 }
        private ICustomFactory GetCustomFactory(Type t, ConfigurationReflectionCache reflectionCache)
        {
            ICustomFactory customFactory = reflectionCache.GetCustomFactory(t);

            return(customFactory);
        }
예제 #9
0
        /// <summary>
        /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
        /// </summary>
        /// <param name="context">Represents the context in which a build-up or tear-down runs.</param>
        /// <param name="name">Unused parameter</param>
        /// <param name="configurationSource">Represents a source for getting configuration</param>
        /// <param name="reflectionCache">Unused parameter.</param>
        /// <returns>Fully initialized instance of a default event logging object</returns>
        public object CreateObject(IBuilderContext context, string name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
        {
            InstrumentationConfigurationSection objectConfiguration = GetConfiguration(configurationSource);

            object createdObject = DoCreateObject((objectConfiguration));

            return(createdObject);
        }
예제 #10
0
 internal ReflectionCachePolicy(ConfigurationReflectionCache reflectionCache)
 {
     this.reflectionCache = reflectionCache;
 }
        private void BindInstrumentationTo(object createdObject, object[] constructorArgs, ConfigurationReflectionCache reflectionCache)
        {
            IInstrumentationAttacher attacher = attacherFactory.CreateBinder(createdObject, constructorArgs, reflectionCache);

            attacher.BindInstrumentation();
        }
        /// <summary>
        /// Attaches the instrumentation events in the <paramref name="createdObject"></paramref> to the
        /// creating instance of the listener object, as defined by the <see cref="InstrumentationListenerAttribute"></see>
        /// on the source class.
        /// </summary>
        /// <param name="instanceName">User-provided instance name given to the instrumenation listener during its instantiation.</param>
        /// <param name="createdObject">Source object used for instrumentation events.</param>
        /// <param name="configurationSource"><see cref="IConfigurationSource"></see> instance used to define whether
        /// instrumentation is enabled or disabled for application.</param>
        /// <param name="reflectionCache">Cache for instrumentation attributes discovered through reflection.</param>
        public void AttachInstrumentation(string instanceName, object createdObject, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
        {
            ArgumentGenerator arguments = new ArgumentGenerator(instanceName);

            AttachInstrumentation(arguments, createdObject, configurationSource, reflectionCache);
        }
예제 #13
0
        /// <summary>
        /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
        /// Returns a new instance of a concrete <see cref="Database"/>, described by the <see cref="ConnectionStringSettings"/>
        /// found in the <paramref name="configurationSource"/> under the name <paramref name="name"/>, plus any additional
        /// configuration information that might describe the the concrete <b>Database</b>.
        /// </summary>
        /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param>
        /// <param name="name">The name of the instance to build, or <see langword="null"/> (<b>Nothing</b> in Visual Basic).</param>
        /// <param name="configurationSource">The source for configuration objects.</param>
        /// <param name="reflectionCache">The cache to use retrieving reflection information.</param>
        /// <returns>A new instance of the appropriate subtype of <typeparamref name="Tobject"/>.</returns>
        /// <exception cref="ConfigurationErrorsException">when the configuration is invalid or <paramref name="name"/> cannot be found.</exception>
        public object CreateObject(IBuilderContext context, string name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
        {
            DatabaseConfigurationView configurationView        = new DatabaseConfigurationView(configurationSource);
            ConnectionStringSettings  connectionStringSettings = configurationView.GetConnectionStringSettings(name);
            DbProviderMapping         mapping = configurationView.GetProviderMapping(name, connectionStringSettings.ProviderName);

            IDatabaseAssembler assembler = GetAssembler(mapping.DatabaseType, name, reflectionCache);
            Database           database  = assembler.Assemble(name, connectionStringSettings, configurationSource);

            return(database);
        }