/// <summary>
        /// public for unittesting purposes.
        /// </summary>
        /// <param name="configurationSource"></param>
        /// <param name="reconfiguringEventSource"></param>
        /// <returns></returns>
        public static IEnumerable<ITypeRegistrationsProvider> CreateTypeRegistrationsProviderLocators(IConfigurationSource configurationSource, IContainerReconfiguringEventSource reconfiguringEventSource)
        {
            TypeRegistrationProvidersConfigurationSection section = configurationSource.GetSection(TypeRegistrationProvidersConfigurationSection.SectionName) as TypeRegistrationProvidersConfigurationSection;
            if (section == null)
            {
                section = new TypeRegistrationProvidersConfigurationSection();
            }

            foreach (TypeRegistrationProviderElement typeRegistrationProviderElement in section.TypeRegistrationProviders)
            {
                if (!string.IsNullOrEmpty(typeRegistrationProviderElement.SectionName) &&
                    !string.IsNullOrEmpty(typeRegistrationProviderElement.ProviderTypeName))
                {
                    throw new ConfigurationErrorsException(
                        string.Format("Type Registration Provider Settings '{0}' cannot declare both sectionName and providerType attributes",
                        typeRegistrationProviderElement.Name));
                }
                if (!string.IsNullOrEmpty(typeRegistrationProviderElement.SectionName))
                {
                    yield return new ConfigSectionLocator(typeRegistrationProviderElement.SectionName, reconfiguringEventSource);
                }
                else if (!string.IsNullOrEmpty(typeRegistrationProviderElement.ProviderTypeName))
                {
                    yield return new TypeLoadingLocator(typeRegistrationProviderElement.ProviderTypeName, reconfiguringEventSource);
                }
            }
        }
        /// <summary>
        /// Construct an instance of <see cref="ConfigSectionLocator"/> that
        /// will look for the given <paramref name="sectionName"/>. It also
        /// registers for the <see cref="IContainerReconfiguringEventSource.ContainerReconfiguring"/>
        /// event, and will request updated type registrations from the section
        /// at that time.
        /// </summary>
        /// <param name="sectionName">Section name in configuration to look for.</param>
        /// <param name="reconfiguringEventSource">Event source to signal when reconfiguration is needed.</param>
        public ConfigSectionLocator(string sectionName, IContainerReconfiguringEventSource reconfiguringEventSource)
            : base(sectionName)
        {
            if(reconfiguringEventSource == null) throw new ArgumentNullException("reconfiguringEventSource");

            reconfiguringEventSource.ContainerReconfiguring += OnContainerReconfiguring;
        }
        /// <summary>
        /// Construct a <see cref="TypeLoadingLocator"/> that will use the
        /// type named in <paramref name="typeName"/> as the provider.
        /// </summary>
        /// <param name="typeName">type to construct as a provider. This type must have a single argument
        /// constructor that takes an <see cref="IConfigurationSource"/> parameter.</param>
        /// <param name="reconfiguringEventSource">The event source containing events raised when the configuration source is changed.</param>
        public TypeLoadingLocator(string typeName, IContainerReconfiguringEventSource reconfiguringEventSource)
            : base(typeName)
        {
            if (reconfiguringEventSource == null) throw new ArgumentNullException("reconfiguringEventSource");

            reconfiguringEventSource.ContainerReconfiguring += OnContainerReconfiguring;
        }
        /// <summary>
        /// Construct a <see cref="TypeLoadingLocator"/> that will use the
        /// type named in <paramref name="typeName"/> as the provider.
        /// </summary>
        /// <param name="typeName">type to construct as a provider. This type must have a single argument
        /// constructor that takes an <see cref="IConfigurationSource"/> parameter.</param>
        /// <param name="reconfiguringEventSource">The event source containing events raised when the configuration source is changed.</param>
        public TypeLoadingLocator(string typeName, IContainerReconfiguringEventSource reconfiguringEventSource)
            : base(typeName)
        {
            if (reconfiguringEventSource == null)
            {
                throw new ArgumentNullException("reconfiguringEventSource");
            }

            reconfiguringEventSource.ContainerReconfiguring += OnContainerReconfiguring;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Construct an instance of <see cref="ConfigSectionLocator"/> that
        /// will look for the given <paramref name="sectionName"/>. It also
        /// registers for the <see cref="IContainerReconfiguringEventSource.ContainerReconfiguring"/>
        /// event, and will request updated type registrations from the section
        /// at that time.
        /// </summary>
        /// <param name="sectionName">Section name in configuration to look for.</param>
        /// <param name="reconfiguringEventSource">Event source to signal when reconfiguration is needed.</param>
        public ConfigSectionLocator(string sectionName, IContainerReconfiguringEventSource reconfiguringEventSource)
            : base(sectionName)
        {
            if (reconfiguringEventSource == null)
            {
                throw new ArgumentNullException("reconfiguringEventSource");
            }

            reconfiguringEventSource.ContainerReconfiguring += OnContainerReconfiguring;
        }
        ///// <summary>
        ///// Create a <see cref="ITypeRegistrationsProvider"/> that contains all the default registration
        ///// providers, honoring any configuration overrides of locators.
        ///// </summary>
        ///// <returns>The <see cref="ITypeRegistrationsProvider"/> that will return all registrations.</returns>
        //public static ITypeRegistrationsProvider CreateProvider(IConfigurationSource configurationSource)
        //{
        //    return CreateProvider(configurationSource, new NullContainerReconfiguringEventSource());
        //}

        /// <summary>
        /// Create a <see cref="ITypeRegistrationsProvider"/> that contains all the default registration
        /// providers, honoring any configuration overrides of locators.
        /// </summary>
        /// <param name="configurationSource">The configuration source to use when creating <see cref="TypeRegistrationsProvider"/>s</param>
        /// <param name="reconfiguringEventSource">The <see cref="IContainerReconfiguringEventSource"/> responsible for raising container reconfiguration events.</param>
        /// <returns>The <see cref="ITypeRegistrationsProvider"/> that will return all registrations.</returns>
        public static ITypeRegistrationsProvider CreateProvider(IConfigurationSource configurationSource, IContainerReconfiguringEventSource reconfiguringEventSource)
        {
            var locators = CreateTypeRegistrationsProviderLocators(configurationSource, reconfiguringEventSource);
            return new CompositeTypeRegistrationsProviderLocator(locators);
        }
        /// <summary>
        /// public for unittesting purposes.
        /// </summary>
        /// <param name="configurationSource"></param>
        /// <param name="reconfiguringEventSource"></param>
        /// <returns></returns>
        public static IEnumerable <ITypeRegistrationsProvider> CreateTypeRegistrationsProviderLocators(IConfigurationSource configurationSource, IContainerReconfiguringEventSource reconfiguringEventSource)
        {
            TypeRegistrationProvidersConfigurationSection section = configurationSource.GetSection(TypeRegistrationProvidersConfigurationSection.SectionName) as TypeRegistrationProvidersConfigurationSection;

            if (section == null)
            {
                section = new TypeRegistrationProvidersConfigurationSection();
            }

            foreach (TypeRegistrationProviderElement typeRegistrationProviderElement in section.TypeRegistrationProviders)
            {
                if (!string.IsNullOrEmpty(typeRegistrationProviderElement.SectionName) &&
                    !string.IsNullOrEmpty(typeRegistrationProviderElement.ProviderTypeName))
                {
                    throw new ConfigurationErrorsException(
                              string.Format("Type Registration Provider Settings '{0}' cannot declare both sectionName and providerType attributes",
                                            typeRegistrationProviderElement.Name));
                }
                if (!string.IsNullOrEmpty(typeRegistrationProviderElement.SectionName))
                {
                    yield return(new ConfigSectionLocator(typeRegistrationProviderElement.SectionName, reconfiguringEventSource));
                }
                else if (!string.IsNullOrEmpty(typeRegistrationProviderElement.ProviderTypeName))
                {
                    yield return(new TypeLoadingLocator(typeRegistrationProviderElement.ProviderTypeName, reconfiguringEventSource));
                }
            }
        }
        ///// <summary>
        ///// Create a <see cref="ITypeRegistrationsProvider"/> that contains all the default registration
        ///// providers, honoring any configuration overrides of locators.
        ///// </summary>
        ///// <returns>The <see cref="ITypeRegistrationsProvider"/> that will return all registrations.</returns>
        //public static ITypeRegistrationsProvider CreateProvider(IConfigurationSource configurationSource)
        //{
        //    return CreateProvider(configurationSource, new NullContainerReconfiguringEventSource());
        //}

        /// <summary>
        /// Create a <see cref="ITypeRegistrationsProvider"/> that contains all the default registration
        /// providers, honoring any configuration overrides of locators.
        /// </summary>
        /// <param name="configurationSource">The configuration source to use when creating <see cref="TypeRegistrationsProvider"/>s</param>
        /// <param name="reconfiguringEventSource">The <see cref="IContainerReconfiguringEventSource"/> responsible for raising container reconfiguration events.</param>
        /// <returns>The <see cref="ITypeRegistrationsProvider"/> that will return all registrations.</returns>
        public static ITypeRegistrationsProvider CreateProvider(IConfigurationSource configurationSource, IContainerReconfiguringEventSource reconfiguringEventSource)
        {
            var locators = CreateTypeRegistrationsProviderLocators(configurationSource, reconfiguringEventSource);

            return(new CompositeTypeRegistrationsProviderLocator(locators));
        }
 /// <summary>
 /// Creates a new <see cref="TypeRegistrationsProvider"/> that will return all the
 /// configuration for entlib blocks.
 /// </summary>
 /// <param name="configurationSource">Configuration source containing any customizations
 /// to the locator list.</param>
 /// <param name="reconfiguringEventSource">Event source notifying of container reconfiguration events.</param>
 /// <returns>The locator.</returns>
 public static ITypeRegistrationsProvider CreateDefaultProvider(IConfigurationSource configurationSource, IContainerReconfiguringEventSource reconfiguringEventSource)
 {
     return ConfigurationBasedTypeRegistrationsProviderFactory.CreateProvider(configurationSource, reconfiguringEventSource);
 }
 /// <summary>
 /// Creates a new <see cref="TypeRegistrationsProvider"/> that will return all the
 /// configuration for entlib blocks.
 /// </summary>
 /// <param name="configurationSource">Configuration source containing any customizations
 /// to the locator list.</param>
 /// <param name="reconfiguringEventSource">Event source notifying of container reconfiguration events.</param>
 /// <returns>The locator.</returns>
 public static ITypeRegistrationsProvider CreateDefaultProvider(IConfigurationSource configurationSource, IContainerReconfiguringEventSource reconfiguringEventSource)
 {
     return(ConfigurationBasedTypeRegistrationsProviderFactory.CreateProvider(configurationSource, reconfiguringEventSource));
 }