Esempio n. 1
0
        //--- Methods ---

        /// <summary>
        /// Load the configuration into a builder
        /// </summary>
        /// <param name="builder">Container builder to public.</param>
        protected override void Load(ContainerBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            foreach (var component in _config["component"])
            {
                var componentDebug         = new DebugStringBuilder(_log.IsDebugEnabled);
                var implementationTypename = component["@implementation"].AsText;
                var type = LoadType(component["@type"]);
                IRegistrationBuilder <object, ConcreteReflectionActivatorData, SingleRegistrationStyle> registrar;
                var name = component["@name"].AsText;
                if (string.IsNullOrEmpty(implementationTypename))
                {
                    componentDebug.AppendFormat("registering concrete type '{0}'", type.FullName);
                    registrar = builder.RegisterType(type);
                }
                else
                {
                    var concreteType = LoadType(implementationTypename);
                    componentDebug.AppendFormat("registering concrete type '{0}' as '{1}'", concreteType.FullName, type.FullName);
                    registrar = builder.RegisterType(concreteType).As(new TypedService(type));
                }
                if (!string.IsNullOrEmpty(name))
                {
                    registrar.Named(name, type);
                    componentDebug.AppendFormat("named '{0}'", name);
                }
                registrar.WithParameters(
                    (from parameter in component["parameters/parameter"]
                     let parameterName = parameter["@name"].AsText
                                         let parameterValue = parameter["@value"].AsText
                                                              select new ResolvedParameter(
                         (p, c) => p.Name == parameterName,
                         (p, c) => SysUtil.ChangeType(parameterValue, p.ParameterType))
                    ).Cast <Parameter>());

                // set scope
                DreamContainerScope scope = _defaultScope;
                var strScope = component["@scope"].AsText;
                if (strScope != null)
                {
                    scope = SysUtil.ParseEnum <DreamContainerScope>(strScope);
                }
                componentDebug.AppendFormat(" in '{0}' scope", scope);
                registrar.InScope(scope);
                if (_log.IsDebugEnabled)
                {
                    _log.Debug(componentDebug.ToString());
                }
            }
        }
Esempio n. 2
0
        //--- Methods ---

        /// <summary>
        /// Load the configuration into a builder
        /// </summary>
        /// <param name="builder">Container builder to public.</param>
        protected override void Load(ContainerBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            foreach (var component in _config["component"])
            {
                var componentDebug         = new DebugStringBuilder(_log.IsDebugEnabled);
                var implementationTypename = component["@implementation"].AsText;
                var type = LoadType(component["@type"]);
                IReflectiveRegistrar registrar;
                if (string.IsNullOrEmpty(implementationTypename))
                {
                    componentDebug.AppendFormat("registering concrete type '{0}'", type.FullName);
                    registrar = builder.Register(type);
                }
                else
                {
                    var concreteType = LoadType(implementationTypename);
                    registrar = builder.Register(concreteType);
                    registrar.As(new TypedService(type));
                    componentDebug.AppendFormat("registering concrete type '{0}' as '{1}'", concreteType.FullName, type.FullName);
                }
                registrar.WithArguments(GetParameters(component));

                // set scope
                DreamContainerScope scope = _defaultScope;
                var strScope = component["@scope"].AsText;
                if (strScope != null)
                {
                    scope = SysUtil.ParseEnum <DreamContainerScope>(strScope);
                }
                componentDebug.AppendFormat(" in '{0}' scope", scope);
                registrar.InScope(scope);

                // set up name
                var name = component["@name"].AsText;
                if (!string.IsNullOrEmpty(name))
                {
                    componentDebug.AppendFormat(" named '{0}'", name);
                    registrar.Named(name);
                }
                if (_log.IsDebugEnabled)
                {
                    _log.Debug(componentDebug.ToString());
                }
            }
        }
        //--- Methods ---
        /// <summary>
        /// Load the configuration into a builder
        /// </summary>
        /// <param name="builder">Container builder to public.</param>
        protected override void Load(ContainerBuilder builder)
        {
            if(builder == null) {
                throw new ArgumentNullException("builder");
            }

            foreach(var component in _config["component"]) {
                var componentDebug = new DebugStringBuilder(_log.IsDebugEnabled);
                var implementationTypename = component["@implementation"].AsText;
                var type = LoadType(component["@type"]);
                IReflectiveRegistrar registrar;
                if(string.IsNullOrEmpty(implementationTypename)) {
                    componentDebug.AppendFormat("registering concrete type '{0}'", type.FullName);
                    registrar = builder.Register(type);
                } else {
                    var concreteType = LoadType(implementationTypename);
                    registrar = builder.Register(concreteType);
                    registrar.As(new TypedService(type));
                    componentDebug.AppendFormat("registering concrete type '{0}' as '{1}'", concreteType.FullName, type.FullName);
                }
                registrar.WithArguments(GetParameters(component));

                // set scope
                DreamContainerScope scope = _defaultScope;
                var strScope = component["@scope"].AsText;
                if(strScope != null) {
                    scope = SysUtil.ParseEnum<DreamContainerScope>(strScope);
                }
                componentDebug.AppendFormat(" in '{0}' scope", scope);
                registrar.InScope(scope);

                // set up name
                var name = component["@name"].AsText;
                if(!string.IsNullOrEmpty(name)) {
                    componentDebug.AppendFormat(" named '{0}'", name);
                    registrar.Named(name);
                }
                if(_log.IsDebugEnabled) {
                    _log.Debug(componentDebug.ToString());
                }
            }
        }