/// <summary> /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code. /// Returns a new instance of a concrete <see cref="Database"/>, described by the <see cref="ConnectionStringSettings"/> /// found in the <paramref name="configurationSource"/> under the name <paramref name="name"/>, plus any additional /// configuration information that might describe the the concrete <b>Database</b>. /// </summary> /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param> /// <param name="name">The name of the instance to build, or <see langword="null"/> (<b>Nothing</b> in Visual Basic).</param> /// <param name="configurationSource">The source for configuration objects.</param> /// <param name="reflectionCache">The cache to use retrieving reflection information.</param> /// <returns>A new instance of the appropriate subtype of <typeparamref name="Tobject"/>.</returns> /// <exception cref="ConfigurationErrorsException">when the configuration is invalid or <paramref name="name"/> cannot be found.</exception> public object CreateObject(IBuilderContext context, string name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) { DatabaseConfigurationView configurationView = new DatabaseConfigurationView(configurationSource); ConnectionStringSettings connectionStringSettings = configurationView.GetConnectionStringSettings(name); DbProviderMapping mapping = configurationView.GetProviderMapping(name, connectionStringSettings.ProviderName); IDatabaseAssembler assembler = GetAssembler(mapping.DatabaseType, name, reflectionCache); Database database = assembler.Assemble(name, connectionStringSettings, configurationSource); return(database); }
/// <summary> /// Returns the <see cref="DbProviderMapping"/> that specifies the mapping between an ADO.NET provider factory and a /// <see cref="Database"/> instance. /// </summary> /// <remarks> /// The mapping based in logical names will be probed first. If there is no success, the default type based mappings /// will be considered. If no default mapping is defined for the provider factory type, the generic database will be used. /// </remarks> /// <param name="name">The name of the <see cref="Database"/> instance.</param> /// <param name="dbProviderName">The logical provider name.</param> /// <returns>The <see cref="DbProviderMapping"/> that matches the <paramref name="dbProviderName"/>.</returns> public DbProviderMapping GetProviderMapping(string name, string dbProviderName) { DatabaseSettings settings = this.DatabaseSettings; if (settings != null) { DbProviderMapping existingMapping = settings.ProviderMappings.Get(dbProviderName); if (existingMapping != null) { return(existingMapping); } } DbProviderMapping defaultMapping = this.GetDefaultMapping(name, dbProviderName); if (defaultMapping != null) { return(defaultMapping); } return(this.GetGenericMapping()); }