protected override void Initialize()
        {
            DatabaseConfigurationView configurationView = new DatabaseConfigurationView(ConfigurationSource);
            string defaultDatabaseName = configurationView.DefaultName;

            foreach (ConnectionStringSettings connectionStringSettings
                     in configurationView.GetConnectionStringSettingsCollection())
            {
                if (IsValidProviderName(connectionStringSettings.ProviderName))
                {
                    DbProviderMapping mapping
                        = configurationView.GetProviderMapping(
                              connectionStringSettings.Name,
                              connectionStringSettings.ProviderName);
                    Type databaseType = mapping.DatabaseType;
                    this.Context.Policies.Set <IBuildKeyMappingPolicy>(
                        new BuildKeyMappingPolicy(new NamedTypeBuildKey(databaseType, connectionStringSettings.Name)),
                        NamedTypeBuildKey.Make <Database>(connectionStringSettings.Name));
                    if (connectionStringSettings.Name == defaultDatabaseName)
                    {
                        this.Context.Policies.Set <IBuildKeyMappingPolicy>(
                            new BuildKeyMappingPolicy(new NamedTypeBuildKey(databaseType, connectionStringSettings.Name)),
                            NamedTypeBuildKey.Make <Database>());
                    }
                    IContainerPolicyCreator policyCreator = GetContainerPolicyCreator(databaseType, null);
                    policyCreator.CreatePolicies(
                        this.Context.Policies,
                        connectionStringSettings.Name,
                        connectionStringSettings,
                        this.ConfigurationSource);
                }
            }
        }
        protected void CreateProvidersPolicies <TProviderBase, TProviderConfigurationBase>(
            IPolicyList policyList,
            string defaultProviderName,
            PolymorphicConfigurationElementCollection <TProviderConfigurationBase> configurationObjects,
            IConfigurationSource configurationSource,
            Func <TProviderConfigurationBase, string> getName)
            where TProviderBase : class
            where TProviderConfigurationBase : NameTypeConfigurationElement, new()
        {
            // set the key mapping for the default, if any
            if (!string.IsNullOrEmpty(defaultProviderName))
            {
                TProviderConfigurationBase defaultData = configurationObjects.Get(defaultProviderName);
                if (defaultData == null)
                {
                    throw new ConfigurationErrorsException(
                              string.Format(
                                  CultureInfo.CurrentCulture,
                                  Resources.ExceptionTheSpecifiedDefaultProviderDoesNotExistInConfiguration,
                                  defaultProviderName,
                                  typeof(TProviderBase).FullName));
                }

                policyList.Set <IBuildKeyMappingPolicy>(
                    new BuildKeyMappingPolicy(new NamedTypeBuildKey(defaultData.Type, getName(defaultData))),
                    new NamedTypeBuildKey(typeof(TProviderBase)));
            }

            // set the policies for the providers
            foreach (TProviderConfigurationBase data in configurationObjects)
            {
                string instanceName = getName(data);

                // key mapping from the provider abstraction to the implementation
                policyList.Set <IBuildKeyMappingPolicy>(
                    new BuildKeyMappingPolicy(new NamedTypeBuildKey(data.Type, instanceName)),
                    new NamedTypeBuildKey(typeof(TProviderBase), instanceName));

                IContainerPolicyCreator policyCreator = GetContainerPolicyCreator(data.GetType(), data.Type);
                policyCreator.CreatePolicies(policyList, instanceName, data, configurationSource);
            }
        }