private IEnumerable <Service> EnumerateComponentServices(ComponentElement component, Assembly defaultAssembly) { if (!string.IsNullOrEmpty(component.Service)) { Type type = this.LoadType(component.Service, defaultAssembly); if (!string.IsNullOrEmpty(component.Name)) { yield return(new KeyedService(component.Name, type)); } else { yield return(new TypedService(type)); } } else { if (!string.IsNullOrEmpty(component.Name)) { throw new ConfigurationErrorsException(string.Format(CultureInfo.CurrentCulture, ConfigurationSettingsReaderResources.ServiceTypeMustBeSpecified, new object[] { component.Name })); } } foreach (ServiceElement current in component.Services) { Type type2 = this.LoadType(current.Type, defaultAssembly); if (!string.IsNullOrEmpty(current.Name)) { yield return(new KeyedService(current.Name, type2)); } else { yield return(new TypedService(type2)); } } yield break; }
private IEnumerable <Service> EnumerateComponentServices(ComponentElement component, Assembly defaultAssembly) { if (!string.IsNullOrEmpty(component.Service)) { var serviceType = LoadType(component.Service, defaultAssembly); if (!string.IsNullOrEmpty(component.Name)) { yield return(new KeyedService(component.Name, serviceType)); } else { yield return(new TypedService(serviceType)); } } else { if (!string.IsNullOrEmpty(component.Name)) { throw new ConfigurationErrorsException(String.Format(CultureInfo.CurrentCulture, ConfigurationSettingsReaderResources.ServiceTypeMustBeSpecified, component.Name)); } } foreach (ServiceElement service in component.Services) { var serviceType = LoadType(service.Type, defaultAssembly); if (!string.IsNullOrEmpty(service.Name)) { yield return(new KeyedService(service.Name, serviceType)); } else { yield return(new TypedService(serviceType)); } } }
/// <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)); } } }
/// <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)); } } }
/// <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 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 { Enforce.ArgumentNotNull(component, "component"); Enforce.ArgumentNotNull(registrar, "registrar"); if (!string.IsNullOrEmpty(component.InjectProperties)) { switch (component.InjectProperties.ToLower()) { case "no": break; case "yes": registrar.PropertiesAutowired(true); break; default: throw new ConfigurationErrorsException(string.Format(CultureInfo.CurrentCulture, ConfigurationSettingsReaderResources.UnrecognisedInjectProperties, component.InjectProperties)); } } }