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);
        }
 internal ReflectionCachePolicy(ConfigurationReflectionCache reflectionCache)
 {
     this.reflectionCache = reflectionCache;
 }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 public object CreateObject(IBuilderContext context, string name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
 {
     return(Create(context, name, configurationSource, reflectionCache));
 }
        public void AttachInstrumentation(string instanceName, object createdObject, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
        {
            ArgumentGenerator arguments = new ArgumentGenerator(instanceName);

            AttachInstrumentation(arguments, createdObject, configurationSource, reflectionCache);
        }
        private void BindInstrumentationTo(object createdObject, object[] constructorArgs, ConfigurationReflectionCache reflectionCache)
        {
            IInstrumentationAttacher attacher = attacherFactory.CreateBinder(createdObject, constructorArgs, reflectionCache);

            attacher.BindInstrumentation();
        }
Ejemplo n.º 7
0
        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);
        }
        private InstrumentationListenerAttribute GetInstrumentationListenerAttribute(object createdObject, ConfigurationReflectionCache reflectionCache)
        {
            Type createdObjectType = createdObject.GetType();
            InstrumentationListenerAttribute listenerAttribute
                = reflectionCache.GetCustomAttribute <InstrumentationListenerAttribute>(createdObjectType, true);

            return(listenerAttribute);
        }
        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));
        }
Ejemplo n.º 10
0
        private static ICustomFactory GetCustomFactory(Type t, ConfigurationReflectionCache reflectionCache)
        {
            ICustomFactory customFactory = reflectionCache.GetCustomFactory(t);

            return(customFactory);
        }
 /// <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));
 }