/// <summary> /// Consume the set of <see cref="TypeRegistration"/> objects and /// configure the associated container. /// </summary> /// <param name="configurationSource">Configuration source to read registrations from.</param> /// <param name="rootProvider"><see cref="ITypeRegistrationsProvider"/> that knows how to /// read the <paramref name="configurationSource"/> and return all relevant type registrations.</param> public void RegisterAll(IConfigurationSource configurationSource, ITypeRegistrationsProvider rootProvider) { RegisterAllCore(configurationSource, rootProvider); this.configurationSource = configurationSource; configurationSource.SourceChanged += OnConfigurationSourceChanged; }
/// <summary> /// Consume the set of <see cref="T:Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.TypeRegistration"/> objects and /// configure the associated container. /// </summary> /// <param name="configurationSource">Configuration source to read registrations from.</param> /// <param name="rootProvider"><see cref="T:Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ITypeRegistrationsProvider"/> that knows how to /// read the <paramref name="configurationSource"/> and return all relevant type registrations.</param> public void RegisterAll(IConfigurationSource configurationSource, ITypeRegistrationsProvider rootProvider) { foreach (TypeRegistration registrationEntry in rootProvider.GetRegistrations(configurationSource)) { Register(registrationEntry); } }
/// <summary> /// Consume the set of /// <see cref="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.TypeRegistration"/> /// objects and configure the associated container. /// </summary> /// <param name="configurationSource"> /// Configuration source to read registrations from. /// </param> /// <param name="rootProvider"> /// <see cref="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ITypeRegistrationsProvider"/> /// that knows how to read the <paramref name="configurationSource"/> /// and return all relevant type registrations. /// </param> /// <remarks> /// <para> /// This method is used by <see cref="M:Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.ConfigureContainer"/> /// to add registrations from a provided <paramref name="configurationSource" /> /// to the Autofac container. /// </para> /// <para> /// At the end of the registration process, a placeholder configuration /// change manager (<see cref="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ConfigurationChangeEventSource"/>) /// will be added to the container if one hasn't already been added. /// This is required because some internal Enterprise Library /// components make the assumption that the container has a configuration /// change manager registered regardless of support. Developers should /// be aware that no action will take place if configuration /// changes even though the component appears to be present in the container. /// </para> /// </remarks> public void RegisterAll(IConfigurationSource configurationSource, ITypeRegistrationsProvider rootProvider) { if (configurationSource == null) { throw new ArgumentNullException("configurationSource"); } if (rootProvider == null) { throw new ArgumentNullException("rootProvider"); } foreach (TypeRegistration registration in rootProvider.GetRegistrations(configurationSource)) { this._builder.RegisterTypeRegistration(registration); } // For some reason you have to manually register an event source // with the container. Unity must somehow do this automatically in // the UnityContainerConfigurator but I can't find it. You need to // do this if you use the Logging application block since the // LoggingUpdateCoordinator requires this type. I'm not sure which // other components might require it. // // Autofac doesn't support changing the container after it's already // built, so rather than implement a ChangeTrackingContainerConfigurator, // we'll just stick a throwaway event source in here. this._builder.RegisterInstance(new ConfigurationChangeEventSourceImpl()).As <ConfigurationChangeEventSource>().PreserveExistingDefaults(); }
public void RegisterAll(Microsoft.Practices.EnterpriseLibrary.Common.Configuration.IConfigurationSource configurationSource, ITypeRegistrationsProvider rootProvider) { foreach (var registration in rootProvider.GetRegistrations(configurationSource)) { register(registration); } }
public void WhenUsingDefaultLocators_ThenDataProviderIsReturned() { locator = TypeRegistrationsProvider.CreateDefaultProvider(); var registrations = locator.GetRegistrations(configSource) .Where(r => r.ServiceType == typeof(Database)); Assert.AreEqual(1, registrations.Count()); }
/// <summary> /// Read the current Enterprise Library configuration in the given <paramref name="configSource"/> /// and supply the corresponding type information to the <paramref name="configurator"/>. /// </summary> /// <param name="locator"><see cref="TypeRegistrationsProvider"/> used to identify what information /// to pull from the configuration file.</param> /// <param name="configurator"><see cref="IContainerConfigurator"/> object used to consume the configuration /// information.</param> /// <param name="configSource">Configuration information.</param> public static void ConfigureContainer(ITypeRegistrationsProvider locator, IContainerConfigurator configurator, IConfigurationSource configSource) { if (configurator == null) throw new ArgumentNullException("configurator"); configurator.RegisterAll(configSource, locator); }
/// <summary> /// Read the current Enterprise Library configuration in the given <paramref name="configSource"/> /// and supply the corresponding type information to the <paramref name="configurator"/>. /// </summary> /// <param name="locator"><see cref="TypeRegistrationsProvider"/> used to identify what information /// to pull from the configuration file.</param> /// <param name="configurator"><see cref="IContainerConfigurator"/> object used to consume the configuration /// information.</param> /// <param name="configSource">Configuration information.</param> public static void ConfigureContainer(ITypeRegistrationsProvider locator, IContainerConfigurator configurator, IConfigurationSource configSource) { if (configurator == null) { throw new ArgumentNullException("configurator"); } configurator.RegisterAll(configSource, locator); }
public void Given() { configurationSource = new MockConfigSource(); var mock = new Mock<ITypeRegistrationsProvider>(); mock.Setup(p => p.GetRegistrations(It.IsAny<IConfigurationSource>())) .Returns(new TypeRegistration[0]); mockRegistrationsProvider = mock.Object; container = new UnityContainer(); configurator = new UnityContainerConfigurator(container); configurator.RegisterAll(configurationSource, mockRegistrationsProvider); }
public void Given() { configurationSource = new MockConfigSource(); var mock = new Mock <ITypeRegistrationsProvider>(); mock.Setup(p => p.GetRegistrations(It.IsAny <IConfigurationSource>())) .Returns(new TypeRegistration[0]); mockRegistrationsProvider = mock.Object; container = new UnityContainer(); configurator = new UnityContainerConfigurator(container); configurator.RegisterAll(configurationSource, mockRegistrationsProvider); }
/// <summary> /// Consume the set of <see cref="TypeRegistration"/> objects and /// configure the associated container. /// </summary> /// <param name="configurationSource">Configuration source to read registrations from.</param> /// <param name="rootProvider"><see cref="ITypeRegistrationsProvider"/> that knows how to /// read the <paramref name="configurationSource"/> and return all relevant type registrations.</param> protected override void RegisterAllCore(IConfigurationSource configurationSource, ITypeRegistrationsProvider rootProvider) { EnterWriteLock(); try { foreach (var registration in rootProvider.GetRegistrations(configurationSource)) { Register(registration); } } finally { ExitWriteLock(); } }
private IEnumerable <TypeRegistration> GetRegistrationsInternal(IConfigurationSource configurationSource, Func <ITypeRegistrationsProvider, IConfigurationSource, IEnumerable <TypeRegistration> > registrationsAccessor) { ITypeRegistrationsProvider provider = null; ConfigurationSection section = configurationSource.GetSection(Name); if (section != null) { provider = section as ITypeRegistrationsProvider; } if (provider != null) { return(registrationsAccessor(provider, configurationSource)); } return(Enumerable.Empty <TypeRegistration>()); }
/// <summary> /// When overridden in a derived class, this method should perform the actual registration with the container. /// </summary> /// <param name="configurationSource">Configuration source to read registrations from.</param> /// <param name="rootProvider"><see cref="ITypeRegistrationsProvider"/> that knows how to /// read the <paramref name="configurationSource"/> and return all relevant type registrations.</param> protected abstract void RegisterAllCore(IConfigurationSource configurationSource, ITypeRegistrationsProvider rootProvider);
protected override void RegisterAllCore(IConfigurationSource configurationSource, ITypeRegistrationsProvider rootProvider) { rootProvider.GetRegistrations(configurationSource); }
public void Given() { configSource = new ConfigSourceBuilder().AddConnectionStringSettings().ConfigSource; locator = new TypeLoadingLocator(BlockSectionNames.DataRegistrationProviderLocatorType); }
/// <summary> /// Consume the set of /// <see cref="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.TypeRegistration"/> /// objects and configure the associated container. /// </summary> /// <param name="configurationSource"> /// Configuration source to read registrations from. /// </param> /// <param name="rootProvider"> /// <see cref="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ITypeRegistrationsProvider"/> /// that knows how to read the <paramref name="configurationSource"/> /// and return all relevant type registrations. /// </param> /// <remarks> /// <para> /// This method is used by <see cref="M:Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.ConfigureContainer"/> /// to add registrations from a provided <paramref name="configurationSource" /> /// to the Autofac container. /// </para> /// <para> /// At the end of the registration process, a placeholder configuration /// change manager (<see cref="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ConfigurationChangeEventSource"/>) /// will be added to the container if one hasn't already been added. /// This is required because some internal Enterprise Library /// components make the assumption that the container has a configuration /// change manager registered regardless of support. Developers should /// be aware that no action will take place if configuration /// changes even though the component appears to be present in the container. /// </para> /// </remarks> public void RegisterAll(IConfigurationSource configurationSource, ITypeRegistrationsProvider rootProvider) { if (configurationSource == null) { throw new ArgumentNullException("configurationSource"); } if (rootProvider == null) { throw new ArgumentNullException("rootProvider"); } foreach (TypeRegistration registration in rootProvider.GetRegistrations(configurationSource)) { this._builder.RegisterTypeRegistration(registration); } // For some reason you have to manually register an event source // with the container. Unity must somehow do this automatically in // the UnityContainerConfigurator but I can't find it. You need to // do this if you use the Logging application block since the // LoggingUpdateCoordinator requires this type. I'm not sure which // other components might require it. // // Autofac doesn't support changing the container after it's already // built, so rather than implement a ChangeTrackingContainerConfigurator, // we'll just stick a throwaway event source in here. this._builder.RegisterInstance(new ConfigurationChangeEventSourceImpl()).As<ConfigurationChangeEventSource>().PreserveExistingDefaults(); }
public void WhenUsingDefaultLocators_ThenDataProviderIsReturned() { locator = TypeRegistrationsProvider.CreateDefaultProvider(); var registrations = locator.GetRegistrations(configSource) .Where(r => r.ServiceType == typeof (Database)); Assert.AreEqual(1, registrations.Count()); }