/// <summary> /// Apply configuration from the given section and named container /// into the given container. /// </summary> /// <param name="container">Unity container to configure.</param> /// <param name="section">Configuration section with config information.</param> /// <param name="containerName">Named container.</param> /// <returns><paramref name="container"/>.</returns> public static IUnityContainer LoadConfiguration(this IUnityContainer container, UnityConfigurationSection section, string containerName) { Guard.ArgumentNotNull(container, "container"); Guard.ArgumentNotNull(section, "section"); section.Configure(container, containerName); return container; }
private void Initialize() { container = new UnityContainer(); configurationSection = Configuration.UnitySection as UnityConfigurationSection; if (configurationSection.Containers.Default != null) { configurationSection.Configure(container); } }
protected UnityConfigurationSection SerializeAndLoadConfig(string filename, Action<ContainerElement> containerInitializer) { var serializer = new ConfigSerializer(filename); var section = new UnityConfigurationSection(); section.SectionExtensions.Add(new SectionExtensionElement() { TypeName = typeof(InterceptionConfigurationExtension).AssemblyQualifiedName }); var container = new ContainerElement(); section.Containers.Add(container); containerInitializer(container); serializer.Save("unity", section); return (UnityConfigurationSection)serializer.Load().GetSection("unity"); }
/// <summary> /// Creates an XML string containing an unmerged view of the <see cref="T:System.Configuration.ConfigurationSection"/> object as a single section to write to a file. /// </summary> /// <returns> /// An XML string containing an unmerged view of the <see cref="T:System.Configuration.ConfigurationSection"/> object. /// </returns> /// <param name="parentElement">The <see cref="T:System.Configuration.ConfigurationElement"/> instance to use as the parent when performing the un-merge.</param> /// <param name="name">The name of the section to create.</param> /// <param name="saveMode">The <see cref="T:System.Configuration.ConfigurationSaveMode"/> instance to use when writing to a string.</param> protected override string SerializeSection(ConfigurationElement parentElement, string name, ConfigurationSaveMode saveMode) { ExtensionElementMap.Clear(); currentSection = this; TypeResolver.SetAliases(this); this.InitializeSectionExtensions(); var sb = new StringBuilder(); using (var writer = MakeXmlWriter(sb)) { writer.WriteStartElement(name, XmlNamespace); writer.WriteAttributeString("xmlns", XmlNamespace); this.TypeAliases.SerializeElementContents(writer, "alias"); this.Namespaces.SerializeElementContents(writer, "namespace"); this.Assemblies.SerializeElementContents(writer, "assembly"); this.SectionExtensions.SerializeElementContents(writer, "sectionExtension"); this.Containers.SerializeElementContents(writer, "container"); writer.WriteEndElement(); } return(sb.ToString()); }
/// <summary> /// Reads XML from the configuration file. /// </summary> /// <param name="reader">The <see cref="T:System.Xml.XmlReader"/> object, which reads from the configuration file. </param> /// <exception cref="T:System.Configuration.ConfigurationErrorsException"><paramref name="reader"/> found no elements in the configuration file.</exception> protected override void DeserializeSection(XmlReader reader) { ExtensionElementMap.Clear(); currentSection = this; base.DeserializeSection(reader); }
/// <summary> /// Apply configuration from the default container in the given section. /// </summary> /// <param name="container">Unity container to configure.</param> /// <param name="section">Configuration section.</param> /// <returns><paramref name="container"/>.</returns> public static IUnityContainer LoadConfiguration(this IUnityContainer container, UnityConfigurationSection section) { Guard.ArgumentNotNull(container, "container"); Guard.ArgumentNotNull(section, "section"); return(container.LoadConfiguration(section, String.Empty)); }
public ExtensionContext(UnityConfigurationSection section, string prefix, bool saveAliases) { this.section = section; this.prefix = prefix; this.saveAliases = saveAliases; }
public ExtensionContext(UnityConfigurationSection section, string prefix) : this(section, prefix, true) { }
private IUnityContainer InitializeContainer(UnityConfigurationSection configurationSection) { var container = new UnityContainer(); RegisterInternalServices(container); var containerElement = configurationSection.Containers.Default; if (containerElement != null) containerElement.Configure(container); else throw new CoreApplicationException("Unable to configure Unity."); return container; }
/// <summary> /// Reads XML from the configuration file. /// </summary> /// <param name="reader">The <see cref="T:System.Xml.XmlReader"/> object, which reads from the configuration file. /// </param><exception cref="T:System.Configuration.ConfigurationErrorsException"><paramref name="reader"/> found no elements in the configuration file. /// </exception> protected override void DeserializeSection(XmlReader reader) { ExtensionElementMap.Clear(); currentSection = this; base.DeserializeSection(reader); }
/// <summary> /// Apply the configuration in the default container element to the given container. /// </summary> /// <param name="container">Container to configure.</param> /// <param name="configuredContainerName">Name of the container element to use to configure the container.</param> /// <returns>The passed in <paramref name="container"/>.</returns> public IUnityContainer Configure(IUnityContainer container, string configuredContainerName) { currentSection = this; TypeResolver.SetAliases(this); var containerElement = GuardContainerExists(configuredContainerName, Containers[configuredContainerName]); containerElement.ConfigureContainer(container); return container; }
/// <summary> /// Apply configuration from the default container in the given section. /// </summary> /// <param name="container">Unity container to configure.</param> /// <param name="section">Configuration section.</param> /// <returns><paramref name="container"/>.</returns> public static IUnityContainer LoadConfiguration(this IUnityContainer container, UnityConfigurationSection section) { Guard.ArgumentNotNull(container, "container"); Guard.ArgumentNotNull(section, "section"); return container.LoadConfiguration(section, ""); }
protected virtual void DoInitialize() { ConfigSection = GetUnitySection(configFileName); }
public ConfigureUsingAppConfig(UnityConfigurationSection section) { this.section = section; }
/// <summary> /// Creates an XML string containing an unmerged view of the <see cref="T:System.Configuration.ConfigurationSection"/> object as a single section to write to a file. /// </summary> /// <returns> /// An XML string containing an unmerged view of the <see cref="T:System.Configuration.ConfigurationSection"/> object. /// </returns> /// <param name="parentElement">The <see cref="T:System.Configuration.ConfigurationElement"/> instance to use as the parent when performing the un-merge. /// </param><param name="name">The name of the section to create. /// </param><param name="saveMode">The <see cref="T:System.Configuration.ConfigurationSaveMode"/> instance to use when writing to a string. /// </param> protected override string SerializeSection(ConfigurationElement parentElement, string name, ConfigurationSaveMode saveMode) { ExtensionElementMap.Clear(); currentSection = this; TypeResolver.SetAliases(this); InitializeSectionExtensions(); var sb = new StringBuilder(); using (var writer = MakeXmlWriter(sb)) { writer.WriteStartElement(name, XmlNamespace); writer.WriteAttributeString("xmlns", XmlNamespace); TypeAliases.SerializeElementContents(writer, "alias"); Namespaces.SerializeElementContents(writer, "namespace"); Assemblies.SerializeElementContents(writer, "assembly"); SectionExtensions.SerializeElementContents(writer, "sectionExtension"); Containers.SerializeElementContents(writer, "container"); writer.WriteEndElement(); } return sb.ToString(); }
/// <summary> /// Construtor do UnityHelper. /// </summary> private UnityHelper() { this._container = new UnityContainer(); this._section = (UnityConfigurationSection)ConfigurationManager.GetSection(SECTION); this._section.Configure(this._container, CONTAINER); }