public virtual bool PushConfiguration(AppConfig config, Type contextType) { DebugCheck.NotNull(config); DebugCheck.NotNull(contextType); Debug.Assert(typeof(DbContext).IsAssignableFrom(contextType)); // Perf optimization: if there is no change to the default app-domain config and if the // context assembly has already been checked for configurations, then avoid creating // and pushing a new configuration since it would be the same as the current one anyway. if (config == AppConfig.DefaultInstance && (contextType == typeof(DbContext) || _knownAssemblies.ContainsKey(contextType.Assembly()))) { return(false); } var configuration = (_loader.TryLoadFromConfig(config) ?? _finder.TryFindConfigurationType(contextType) ?? typeof(DbConfiguration)) .CreateInstance <DbConfiguration>(Strings.CreateInstance_BadDbConfigurationType) .InternalConfiguration; configuration.SwitchInRootResolver(_configuration.Value.RootResolver); configuration.AddAppConfigResolver(new AppConfigDependencyResolver(config, configuration)); foreach (var handler in _loader.GetOnLoadedHandlers(config)) { configuration.AddOnLoadedHandler(handler); } lock (_lock) { _configurationOverrides.Value.Add(Tuple.Create(config, configuration)); } configuration.Lock(); return(true); }
public DbConfigurationManager(DbConfigurationLoader loader, DbConfigurationFinder finder) { DebugCheck.NotNull(loader); DebugCheck.NotNull(finder); _loader = loader; _finder = finder; _configuration = new Lazy <InternalConfiguration>( () => { var configuration = _newConfiguration ?? _newConfigurationType.CreateInstance <DbConfiguration>( Strings.CreateInstance_BadDbConfigurationType); foreach (var handler in _loader.GetOnLoadedHandlers(AppConfig.DefaultInstance)) { configuration.InternalConfiguration.AddOnLoadedHandler(handler); } configuration.InternalConfiguration.Lock(); return(configuration.InternalConfiguration); }); }