Пример #1
0
        /// <summary>
        /// Sets the scope model for the component.
        /// </summary>
        /// <param name="component">The component.</param>
        /// <param name="registrar">The registrar.</param>
        protected virtual void SetScope <TReflectionActivatorData, TSingleRegistrationStyle>(ComponentElement component, IRegistrationBuilder <object, TReflectionActivatorData, TSingleRegistrationStyle> registrar)
            where TReflectionActivatorData : ReflectionActivatorData
            where TSingleRegistrationStyle : SingleRegistrationStyle
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }
            if (registrar == null)
            {
                throw new ArgumentNullException("registrar");
            }

            if (!string.IsNullOrEmpty(component.InstanceScope))
            {
                switch (component.InstanceScope.ToLower())
                {
                case "single-instance":
                    registrar.SingleInstance();
                    break;

                case "per-lifetime-scope":
                    registrar.InstancePerLifetimeScope();
                    break;

                case "per-dependency":
                    registrar.InstancePerDependency();
                    break;

                default:
                    throw new ConfigurationErrorsException(string.Format(CultureInfo.CurrentCulture,
                                                                         ConfigurationSettingsReaderResources.UnrecognisedScope, component.InstanceScope));
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Sets the ownership model of the component.
        /// </summary>
        /// <param name="component">The component.</param>
        /// <param name="registrar">The registrar.</param>
        protected virtual void SetOwnership <TReflectionActivatorData, TSingleRegistrationStyle>(ComponentElement component, IRegistrationBuilder <object, TReflectionActivatorData, TSingleRegistrationStyle> registrar)
            where TReflectionActivatorData : ReflectionActivatorData
            where TSingleRegistrationStyle : SingleRegistrationStyle
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }
            if (registrar == null)
            {
                throw new ArgumentNullException("registrar");
            }

            if (!string.IsNullOrEmpty(component.Ownership))
            {
                switch (component.Ownership.ToLower())
                {
                case "lifetime-scope":
                    registrar.OwnedByLifetimeScope();
                    break;

                case "external":
                    registrar.ExternallyOwned();
                    break;

                default:
                    throw new ConfigurationErrorsException(string.Format(CultureInfo.CurrentCulture,
                                                                         ConfigurationSettingsReaderResources.UnrecognisedOwnership, component.Ownership));
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Sets the property injection mode for the component.
        /// </summary>
        /// <param name="component">The component.</param>
        /// <param name="registrar">The registrar.</param>
        protected virtual void SetInjectProperties <TReflectionActivatorData, TSingleRegistrationStyle>(ComponentElement component, IRegistrationBuilder <object, TReflectionActivatorData, TSingleRegistrationStyle> registrar)
            where TReflectionActivatorData : ReflectionActivatorData
            where TSingleRegistrationStyle : SingleRegistrationStyle
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }
            if (registrar == null)
            {
                throw new ArgumentNullException("registrar");
            }

            if (!string.IsNullOrEmpty(component.InjectProperties))
            {
                switch (component.InjectProperties.ToLower())
                {
                case "no":
                    break;

                case "yes":
                    registrar.PropertiesAutowired(PropertyWiringFlags.AllowCircularDependencies);
                    break;

                default:
                    throw new ConfigurationErrorsException(string.Format(CultureInfo.CurrentCulture,
                                                                         ConfigurationSettingsReaderResources.UnrecognisedInjectProperties, component.InjectProperties));
                }
            }
        }
        /// <summary>
        /// Sets the scope model for the component.
        /// </summary>
        /// <param name="component">The component.</param>
        /// <param name="registrar">The registrar.</param>
        protected virtual void SetScope <TReflectionActivatorData, TSingleRegistrationStyle>(ComponentElement component, IRegistrationBuilder <object, TReflectionActivatorData, TSingleRegistrationStyle> registrar)
            where TReflectionActivatorData : ReflectionActivatorData
            where TSingleRegistrationStyle : SingleRegistrationStyle
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }
            if (registrar == null)
            {
                throw new ArgumentNullException("registrar");
            }

            if (!string.IsNullOrEmpty(component.InstanceScope))
            {
                switch (component.InstanceScope.ToLower())
                {
                case "single-instance":
                    registrar.SingleInstance();
                    break;

                case "per-lifetime-scope":
                    registrar.InstancePerLifetimeScope();
                    break;

                case "per-dependency":
                    registrar.InstancePerDependency();
                    break;

                default:
                    throw new ConfigurationErrorsException(string.Format(CultureInfo.CurrentCulture,
                                                                         "The value '{0}' is not valid for the instance-scope attribute. Valid values are 'single-instance', 'per-dependency' (the default) and 'per-lifetime-scope'.", component.InstanceScope));
                }
            }
        }
        /// <summary>
        /// Sets the ownership model of the component.
        /// </summary>
        /// <param name="component">The component.</param>
        /// <param name="registrar">The registrar.</param>
        protected virtual void SetOwnership <TReflectionActivatorData, TSingleRegistrationStyle>(ComponentElement component, IRegistrationBuilder <object, TReflectionActivatorData, TSingleRegistrationStyle> registrar)
            where TReflectionActivatorData : ReflectionActivatorData
            where TSingleRegistrationStyle : SingleRegistrationStyle
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }
            if (registrar == null)
            {
                throw new ArgumentNullException("registrar");
            }

            if (!string.IsNullOrEmpty(component.Ownership))
            {
                switch (component.Ownership.ToLower())
                {
                case "lifetime-scope":
                    registrar.OwnedByLifetimeScope();
                    break;

                case "external":
                    registrar.ExternallyOwned();
                    break;

                default:
                    throw new ConfigurationErrorsException(string.Format(CultureInfo.CurrentCulture,
                                                                         "The value '{0}' is not valid for the ownership attribute. Valid values are 'lifetime-scope' (the default) and 'external'.", component.Ownership));
                }
            }
        }
        /// <summary>
        /// Sets the property injection mode for the component.
        /// </summary>
        /// <param name="component">The component.</param>
        /// <param name="registrar">The registrar.</param>
        protected virtual void SetInjectProperties <TReflectionActivatorData, TSingleRegistrationStyle>(ComponentElement component, IRegistrationBuilder <object, TReflectionActivatorData, TSingleRegistrationStyle> registrar)
            where TReflectionActivatorData : ReflectionActivatorData
            where TSingleRegistrationStyle : SingleRegistrationStyle
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }
            if (registrar == null)
            {
                throw new ArgumentNullException("registrar");
            }

            if (!string.IsNullOrEmpty(component.InjectProperties))
            {
                switch (component.InjectProperties.ToLower())
                {
                case "no":
                    break;

                case "yes":
                    registrar.PropertiesAutowired(PropertyWiringFlags.AllowCircularDependencies);
                    break;

                default:
                    throw new ConfigurationErrorsException(string.Format(CultureInfo.CurrentCulture,
                                                                         "The value '{0}' is not valid for the inject-properties attribute. Valid values are 'yes' and 'no'.", component.InjectProperties));
                }
            }
        }