private void EnsureConverterInitialized(IKernel kernel) { if(converter == null) { converter = kernel.GetConversionManager(); } }
protected virtual void SetUpComponents(IConfiguration[] configurations, IWindsorContainer container, IConversionManager converter) { foreach (var component in configurations) { var implementation = GetType(converter, component.Attributes["type"]); var firstService = GetType(converter, component.Attributes["service"]); var services = new HashSet<Type>(); if (firstService != null) { services.Add(firstService); } CollectAdditionalServices(component, converter, services); var name = default(string); if (implementation != null) { AssertImplementsService(component, firstService, implementation); var defaults = CastleComponentAttribute.GetDefaultsFor(implementation); if (defaults.ServicesSpecifiedExplicitly && services.Count == 0) { defaults.Services.ForEach(s => services.Add(s)); } name = GetName(defaults, component); } if (services.Count == 0 && implementation == null) { continue; } container.Register(Component.For(services).ImplementedBy(implementation).Named(name)); } }
/// <summary> /// Constructor /// </summary> public RelativePathSubDependencyResolver(IKernel kernel) { m_converter = (IConversionManager)kernel.GetSubSystem(SubSystemConstants.ConversionManagerKey); SettingsSubSystem settingsSubSystem = kernel.GetSettingsSubSystem(); settingsSubSystem.ResolveRelativePaths = true; VALUES = new Dictionary<string, object>(); }
/// <summary> /// Adds the properties as optional dependencies of this component. /// </summary> /// <param name="kernel"></param> /// <param name="model"></param> public virtual void ProcessModel(IKernel kernel, ComponentModel model) { if (converter == null) { converter = (IConversionManager) kernel.GetSubSystem( SubSystemConstants.ConversionManagerKey ); } InspectProperties(model); }
protected virtual void SetUpInstallers(IConfiguration[] installers, IWindsorContainer container, IConversionManager converter) { var instances = new Dictionary<Type, IWindsorInstaller>(); foreach (var installer in installers) { AddInstaller(installer, instances, converter); } if (instances.Count != 0) { container.Install(instances.Values.ToArray()); } }
private void AddInstaller(IConfiguration installer, Dictionary<Type, IWindsorInstaller> cache, IConversionManager conversionManager, ICollection<Assembly> assemblies) { var typeName = installer.Attributes["type"]; if (string.IsNullOrEmpty(typeName) == false) { var type = conversionManager.PerformConversion<Type>(typeName); AddInstaller(cache, type); return; } assemblyName = installer.Attributes["assembly"]; if (string.IsNullOrEmpty(assemblyName) == false) { var assembly = ReflectionUtil.GetAssemblyNamed(assemblyName); if (assemblies.Contains(assembly)) { return; } assemblies.Add(assembly); GetAssemblyInstallers(cache, assembly); return; } #if !SILVERLIGHT var directory = installer.Attributes["directory"]; var mask = installer.Attributes["fileMask"]; var token = installer.Attributes["publicKeyToken"]; Debug.Assert(directory != null, "directory != null"); var assemblyFilter = new AssemblyFilter(directory, mask); if (token != null) { assemblyFilter.WithKeyToken(token); } foreach (var assembly in ReflectionUtil.GetAssemblies(assemblyFilter)) { if (assemblies.Contains(assembly)) { continue; } assemblies.Add(assembly); GetAssemblyInstallers(cache, assembly); } #endif }
private void AddInstaller(IConfiguration installer, Dictionary<Type, IWindsorInstaller> cache, IConversionManager conversionManager) { var typeName = installer.Attributes["type"]; if (string.IsNullOrEmpty(typeName) == false) { var type = conversionManager.PerformConversion(typeName, typeof(Type)) as Type; AddInstaller(cache, type); return; } Debug.Assert(string.IsNullOrEmpty(installer.Attributes["assembly"]) == false); var types = Assembly.Load(installer.Attributes["assembly"]).GetExportedTypes(); foreach (var type in InstallerTypes(types)) { AddInstaller(cache, type); } }
public virtual void ProcessModel(IKernel kernel, ComponentModel model) { if (converter == null) { converter = (IConversionManager) kernel.GetSubSystem(SubSystemConstants.ConversionManagerKey); } var targetType = model.Implementation; var constructors = targetType.GetConstructors(BindingFlags.Public | BindingFlags.Instance); foreach (var constructor in constructors) { // We register each public constructor // and let the ComponentFactory select an // eligible amongst the candidates later model.Constructors.Add(CreateConstructorCandidate(model, constructor)); } }
protected virtual void SetUpInstallers(IConfiguration[] installers, IWindsorContainer container, IConversionManager converter) { var instances = new Dictionary<Type, IWindsorInstaller>(); ICollection<Assembly> assemblies = #if SL3 new List<Assembly>(); #else new HashSet<Assembly>(); #endif foreach (var installer in installers) { AddInstaller(installer, instances, converter, assemblies); } if (instances.Count != 0) { container.Install(instances.Values.ToArray()); } }
public void ProcessModel(IKernel kernel, ComponentModel model) { if (model.Configuration == null) return; var interfaces = model.Configuration.Children["additionalInterfaces"]; if (interfaces == null) return; if(converter == null) { converter = kernel.GetConversionManager(); } var list = new List<Type>(); foreach (var @interface in interfaces.Children .Where(c => c.Name.Equals("add", StringComparison.InvariantCultureIgnoreCase))) { var interfaceTypeName = @interface.Attributes["interface"]; list.Add(converter.PerformConversion<Type>(interfaceTypeName)); } var options = ProxyUtil.ObtainProxyOptions(model, true); options.AddAdditionalInterfaces(list.ToArray()); }
private static IReference <IProxyGenerationHook> ObtainProxyHook(IConfiguration config, IConversionManager converter) { IProxyGenerationHook hook = null; if (config != null) { var hookAttrib = config.Attributes[Constants.ControlProxyHookAttrib]; if (hookAttrib != null) { var hookComponent = ReferenceExpressionUtil.ExtractComponentKey(hookAttrib); if (hookComponent != null) { return(new ComponentReference <IProxyGenerationHook>("synchronize-proxy-generation-hook", hookComponent)); } var hookType = converter.PerformConversion <Type>(hookAttrib); if (hookType.Is <IProxyGenerationHook>() == false) { var message = String.Format("The specified controlProxyHook does " + "not implement the interface {1}. Type {0}", hookType.FullName, typeof(IProxyGenerationHook).Name); throw new ConfigurationErrorsException(message); } hook = hookType.CreateInstance <IProxyGenerationHook>(); } } if (hook == null) { hook = SynchronizeProxyHook.Instance; } return(new InstanceReference <IProxyGenerationHook>(hook)); }
private void CollectAdditionalServices(IConfiguration component, IConversionManager converter, ICollection<Type> services) { var forwardedTypes = component.Children["forwardedTypes"]; if (forwardedTypes == null) { return; } foreach (var forwardedType in forwardedTypes.Children) { var forwardedServiceTypeName = forwardedType.Attributes["service"]; try { services.Add(converter.PerformConversion<Type>(forwardedServiceTypeName)); } catch (ConverterException e) { throw new ComponentRegistrationException( string.Format("Component {0} defines invalid forwarded type.", component.Attributes["id"]), e); } } }
/// <summary> /// Initializes a new instance of the <see cref = "SynchronizeMetaInfoStore" /> class. /// </summary> /// <param name = "conversionManager"></param> public SynchronizeMetaInfoStore(IConversionManager conversionManager) { converter = conversionManager; }
/// <summary> /// Initializes a new instance of the <see cref = "CreateOnUIThreadInspector" /> class. /// </summary> /// <param name = "config">The config.</param> /// <param name = "converter"></param> public CreateOnUIThreadInspector(IConfiguration config, IConversionManager converter) { marshalingControl = new MarshalingControl(); controlProxyHook = ObtainProxyHook(config, converter); }
protected virtual void SetUpComponents(IConfiguration[] configurations, IWindsorContainer container, IConversionManager converter) { foreach (IConfiguration component in configurations) { var id = component.Attributes["id"]; var typeName = component.Attributes["type"]; var serviceTypeName = component.Attributes["service"]; if (string.IsNullOrEmpty(typeName)) { continue; } var type = converter.PerformConversion<Type>(typeName); var service = type; if (!string.IsNullOrEmpty(serviceTypeName)) { service = converter.PerformConversion<Type>(serviceTypeName); } AssertImplementsService(id, service, type); Debug.Assert(id != null); Debug.Assert(type != null); Debug.Assert(service != null); container.Register(Component.For(service).ImplementedBy(type).Named(id)); SetUpComponentForwardedTypes(container.Kernel as IKernelInternal, component, typeName, id, converter); } }
private static void DeserializeElement(XmlNode node, IConfigurationStore store, IConversionManager converter) { if (ContainersNodeName.Equals(node.Name)) { DeserializeContainers(node.ChildNodes, store); } else if (FacilitiesNodeName.Equals(node.Name)) { DeserializeFacilities(node.ChildNodes, store, converter); } else if (InstallersNodeName.Equals(node.Name)) { DeserializeInstallers(node.ChildNodes, store); } else if (ComponentsNodeName.Equals(node.Name)) { DeserializeComponents(node.ChildNodes, store, converter); } else { var message = string.Format( "Configuration parser encountered <{0}>, but it was expecting to find " + "<{1}>, <{2}> or <{3}>. There might be either a typo on <{0}> or " + "you might have forgotten to nest it properly.", node.Name, InstallersNodeName, FacilitiesNodeName, ComponentsNodeName); throw new ConfigurationProcessingException(message); } }
private static void DeserializeFacilities(XmlNodeList nodes, IConfigurationStore store, IConversionManager converter) { foreach (XmlNode node in nodes) { if (node.NodeType != XmlNodeType.Element) { continue; } AssertNodeName(node, FacilityNodeName); DeserializeFacility(node, store, converter); } }
protected virtual void SetUpFacilities(IConfiguration[] configurations, IWindsorContainer container, IConversionManager converter) { foreach (var facility in configurations) { var type = converter.PerformConversion <Type>(facility.Attributes["type"]); var facilityInstance = type.CreateInstance <IFacility>(); Debug.Assert(facilityInstance != null); container.AddFacility(facilityInstance); } }
protected virtual void SetUpComponents(IConfiguration[] configurations, IWindsorContainer container, IConversionManager converter) { foreach (var component in configurations) { var implementation = GetType(converter, component.Attributes["type"]); var firstService = GetType(converter, component.Attributes["service"]); var services = new HashSet <Type>(); if (firstService != null) { services.Add(firstService); } CollectAdditionalServices(component, converter, services); var name = default(string); if (implementation != null) { AssertImplementsService(component, firstService, implementation); var defaults = CastleComponentAttribute.GetDefaultsFor(implementation); if (defaults.ServicesSpecifiedExplicitly && services.Count == 0) { defaults.Services.ForEach(s => services.Add(s)); } name = GetName(defaults, component); } if (services.Count == 0 && implementation == null) { continue; } container.Register(Component.For(services).ImplementedBy(implementation).Named(name)); } }
public PropertiesDependenciesModelInspector(IConversionManager converter) { this.converter = converter; }
public ComponentActivatorInspector(IConversionManager converter) { this.converter = converter; }
private static Type ObtainType(String typeName, IConversionManager converter) { return (Type)converter.PerformConversion(typeName, typeof(Type)); }
protected static void Deserialize(XmlNode section, IConfigurationStore store, IConversionManager converter) { foreach (XmlNode node in section) { if (XmlConfigurationDeserializer.IsTextNode(node)) { throw new ConfigurationProcessingException(String.Format("{0} cannot contain text nodes", node.Name)); } if (node.NodeType == XmlNodeType.Element) { DeserializeElement(node, store, converter); } } }
private static void DeserializeFacility(XmlNode node, IConfigurationStore store, IConversionManager converter) { var config = XmlConfigurationDeserializer.GetDeserializedNode(node); var typeName = GetRequiredAttributeValue(config, "type"); var type = converter.PerformConversion <Type>(typeName); AddFacilityConfig(type.FullName, config, store); }
private static void DeserializeComponents(XmlNodeList nodes, IConfigurationStore store, IConversionManager converter) { foreach(XmlNode node in nodes) { if (node.NodeType != XmlNodeType.Element) continue; AssertNodeName(node, ComponentNodeName); DeserializeComponent(node, store, converter); } }
protected virtual void SetUpFacilities(IConfiguration[] configurations, IWindsorContainer container, IConversionManager converter) { foreach (var facility in configurations) { var type = converter.PerformConversion<Type>(facility.Attributes["type"]); var facilityInstance = type.CreateInstance<IFacility>(); Debug.Assert(facilityInstance != null); container.AddFacility(facilityInstance); } }
protected virtual void SetUpFacilities(IConfiguration[] configurations, IWindsorContainer container, IConversionManager converter) { foreach (IConfiguration facility in configurations) { var id = facility.Attributes["id"]; var typeName = facility.Attributes["type"]; if (string.IsNullOrEmpty(typeName)) { continue; } var type = converter.PerformConversion<Type>(typeName); var facilityInstance = ReflectionUtil.CreateInstance<IFacility>(type); Debug.Assert(id != null); Debug.Assert(facilityInstance != null); container.AddFacility(id, facilityInstance); } }
private void CollectForwardedTypes(IKernelInternal kernel, IConfiguration component, string typeName, string id, IConversionManager converter, List<Type> services) { if (kernel == null) { return; } var forwardedTypes = component.Children["forwardedTypes"]; if (forwardedTypes == null) { return; } foreach (var forwardedType in forwardedTypes.Children .Where(c => c.Name.Trim().Equals("add", StringComparison.InvariantCultureIgnoreCase))) { var forwardedServiceTypeName = forwardedType.Attributes["service"]; try { services.Add(converter.PerformConversion<Type>(forwardedServiceTypeName)); } catch (Exception e) { throw new Exception( string.Format("Component {0}-{1} defines invalid forwarded type.", id ?? string.Empty, typeName), e); } } }
private static IReference<IProxyGenerationHook> ObtainProxyHook(IConfiguration config, IConversionManager converter) { IProxyGenerationHook hook = null; if (config != null) { var hookAttrib = config.Attributes[Constants.ControlProxyHookAttrib]; if (hookAttrib != null) { var hookComponent = ReferenceExpressionUtil.ExtractComponentName(hookAttrib); if (hookComponent != null) { return new ComponentReference<IProxyGenerationHook>(hookComponent); } var hookType = converter.PerformConversion<Type>(hookAttrib); if (hookType.Is<IProxyGenerationHook>() == false) { var message = String.Format("The specified controlProxyHook does " + "not implement the interface {1}. Type {0}", hookType.FullName, typeof(IProxyGenerationHook).FullName); throw new ConfigurationErrorsException(message); } hook = hookType.CreateInstance<IProxyGenerationHook>(); } } if (hook == null) { hook = SynchronizeProxyHook.Instance; } return new InstanceReference<IProxyGenerationHook>(hook); }
public ComponentProxyInspector(IConversionManager converter) { this.converter = converter; }
private static void DeserializeComponent(XmlNode node, IConfigurationStore store, IConversionManager converter) { var config = XmlConfigurationDeserializer.GetDeserializedNode(node); var id = config.Attributes["id"]; if (string.IsNullOrEmpty(id)) { var type = converter.PerformConversion <Type>(config.Attributes["type"]); id = type.FullName; config.Attributes["id"] = id; config.Attributes.Add("id-automatic", bool.TrueString); } AddComponentConfig(id, config, store); }
protected virtual void SetUpComponents(IConfiguration[] configurations, IWindsorContainer container, IConversionManager converter) { foreach (var component in configurations) { var id = component.Attributes["id"]; var typeName = component.Attributes["type"]; var serviceTypeName = component.Attributes["service"]; if (string.IsNullOrEmpty(typeName)) { continue; } var type = converter.PerformConversion <Type>(typeName); var service = type; if (!string.IsNullOrEmpty(serviceTypeName)) { service = converter.PerformConversion <Type>(serviceTypeName); } AssertImplementsService(id, service, type); Debug.Assert(id != null); Debug.Assert(type != null); Debug.Assert(service != null); var services = new List <Type> { service }; CollectForwardedTypes(container.Kernel as IKernelInternal, component, typeName, id, converter, services); var registration = Component.For(services).ImplementedBy(type); if (component.Attributes["id-automatic"] == true.ToString()) { container.Register(registration.NamedAutomatically(id)); } else { container.Register(registration.Named(id)); } } }
private Type GetType(IConversionManager converter, string typeName) { if (typeName == null) { return null; } return converter.PerformConversion<Type>(typeName); }
private void SetUpComponentForwardedTypes(IWindsorContainer container, IConfiguration component, string typeName, string id, IConversionManager converter) { var forwardedTypes = component.Children["forwardedTypes"]; if (forwardedTypes == null) return; var forwarded = new List<Type>(); foreach (var forwardedType in forwardedTypes.Children .Where(c => c.Name.Equals("add", StringComparison.InvariantCultureIgnoreCase))) { var forwardedServiceTypeName = forwardedType.Attributes["service"]; try { forwarded.Add(ObtainType(forwardedServiceTypeName,converter)); } catch (Exception e) { throw new Exception( string.Format("Component {0}-{1} defines invalid forwarded type.", id ?? string.Empty, typeName), e); } } foreach (var forwadedType in forwarded) { container.Kernel.RegisterHandlerForwarding(forwadedType, id); } }
private static void DeserializeComponent(XmlNode node, IConfigurationStore store, IConversionManager converter) { var config = XmlConfigurationDeserializer.GetDeserializedNode(node); var id = config.Attributes["id"]; if(string.IsNullOrEmpty(id)) { var type = converter.PerformConversion<Type>(config.Attributes["type"]); id = type.FullName; config.Attributes["id"] = id; config.Attributes.Add("id-automatic", true.ToString()); } AddComponentConfig(id, config, store); }
protected virtual void SetUpComponents(IConfiguration[] configurations, IWindsorContainer container, IConversionManager converter) { foreach (var component in configurations) { var id = component.Attributes["id"]; var typeName = component.Attributes["type"]; var serviceTypeName = component.Attributes["service"]; if (string.IsNullOrEmpty(typeName)) { continue; } var type = converter.PerformConversion<Type>(typeName); var service = type; if (!string.IsNullOrEmpty(serviceTypeName)) { service = converter.PerformConversion<Type>(serviceTypeName); } AssertImplementsService(id, service, type); Debug.Assert(id != null); Debug.Assert(type != null); Debug.Assert(service != null); var services = new List<Type> { service }; CollectForwardedTypes(container.Kernel as IKernelInternal, component, typeName, id, converter, services); var registration = Component.For(services).ImplementedBy(type); if (component.Attributes["id-automatic"] == true.ToString()) { container.Register(registration.NamedAutomatically(id)); } else { container.Register(registration.Named(id)); } } }
protected static void Deserialize(XmlNode section, IConfigurationStore store, IConversionManager converter) { foreach(XmlNode node in section) { if (XmlConfigurationDeserializer.IsTextNode(node)) { string message = String.Format("{0} cannot contain text nodes", node.Name); throw new Exception(message); } if (node.NodeType == XmlNodeType.Element) { DeserializeElement(node, store, converter); } } }
protected virtual void SetUpFacilities(IConfiguration[] configurations, IWindsorContainer container, IConversionManager converter) { foreach(IConfiguration facility in configurations) { string id = facility.Attributes["id"]; string typeName = facility.Attributes["type"]; if (string.IsNullOrEmpty(typeName)) continue; Type type = ObtainType(typeName, converter); IFacility facilityInstance = InstantiateFacility(type); Debug.Assert( id != null ); Debug.Assert( facilityInstance != null ); container.AddFacility(id, facilityInstance); } }
protected virtual void SetUpComponents(IConfiguration[] configurations, IWindsorContainer container, IConversionManager converter) { foreach(IConfiguration component in configurations) { var id = component.Attributes["id"]; var typeName = component.Attributes["type"]; var serviceTypeName = component.Attributes["service"]; if (string.IsNullOrEmpty(typeName)) continue; Type type = ObtainType(typeName,converter); Type service = type; if (!string.IsNullOrEmpty(serviceTypeName)) { service = ObtainType(serviceTypeName,converter); } AssertImplementsService(id, service, type); Debug.Assert( id != null ); Debug.Assert( type != null ); Debug.Assert( service != null ); container.AddComponent(id, service, type); SetUpComponentForwardedTypes(container, component, typeName, id,converter); } }
/// <summary> /// Initializes a new instance of the <see cref="AppSettingsProvider"/> class. /// </summary> /// <param name="conversionManager">Used to convert settings to their required types.</param> public AppSettingsProvider(IConversionManager conversionManager) : base(conversionManager) { }