/// <summary> /// Default constructor /// </summary> /// <param name="scopeProvider"></param> /// <param name="logger"></param> /// <param name="syntaxProviders"></param> internal DatabaseContext(IScopeProviderInternal scopeProvider, ILogger logger, SqlSyntaxProviders syntaxProviders) { if (scopeProvider == null) { throw new ArgumentNullException("scopeProvider"); } if (logger == null) { throw new ArgumentNullException("logger"); } if (syntaxProviders == null) { throw new ArgumentNullException("syntaxProviders"); } ScopeProvider = scopeProvider; _logger = logger; _syntaxProviders = syntaxProviders; }
/// <summary> /// Default constructor /// </summary> /// <param name="factory"></param> /// <param name="logger"></param> /// <param name="syntaxProviders"></param> public DatabaseContext(IDatabaseFactory factory, ILogger logger, SqlSyntaxProviders syntaxProviders) { if (factory == null) { throw new ArgumentNullException("factory"); } if (logger == null) { throw new ArgumentNullException("logger"); } if (syntaxProviders == null) { throw new ArgumentNullException("syntaxProviders"); } _factory = factory; _logger = logger; _syntaxProviders = syntaxProviders; }
/// <summary> /// Default constructor /// </summary> /// <param name="factory"></param> /// <param name="logger"></param> /// <param name="syntaxProviders"></param> public DatabaseContext(IDatabaseFactory factory, ILogger logger, SqlSyntaxProviders syntaxProviders) { if (factory == null) { throw new ArgumentNullException("factory"); } if (logger == null) { throw new ArgumentNullException("logger"); } if (syntaxProviders == null) { throw new ArgumentNullException("syntaxProviders"); } var asDbFactory2 = factory as IDatabaseFactory2; ScopeProvider = asDbFactory2 == null ? new ScopeProvider(new DatabaseFactoryWrapper(factory)) : new ScopeProvider(asDbFactory2); _logger = logger; _syntaxProviders = syntaxProviders; }
public virtual IBootManager Initialize() { if (_isInitialized) { throw new InvalidOperationException("The boot manager has already been initialized"); } InitializeLoggerResolver(); InitializeProfilerResolver(); ProfilingLogger = ProfilingLogger ?? new ProfilingLogger(LoggerResolver.Current.Logger, ProfilerResolver.Current.Profiler); _timer = ProfilingLogger.TraceDuration <CoreBootManager>( string.Format("Umbraco {0} application starting on {1}", UmbracoVersion.GetSemanticVersion().ToSemanticString(), NetworkHelper.MachineName), "Umbraco application startup complete"); ApplicationCache = CreateApplicationCache(); //create and set the plugin manager (I'd much prefer to not use this singleton anymore but many things are using it unfortunately and // the way that it is setup, there must only ever be one per app so without IoC it would be hard to make this not a singleton) PluginManager = new PluginManager(ServiceProvider, ApplicationCache.RuntimeCache, ProfilingLogger); PluginManager.Current = PluginManager; //Create the legacy prop-eds mapping LegacyPropertyEditorIdToAliasConverter.CreateMappingsForCoreEditors(); LegacyParameterEditorAliasConverter.CreateMappingsForCoreEditors(); //create database and service contexts for the app context var dbFactory = new DefaultDatabaseFactory(Constants.System.UmbracoConnectionName, ProfilingLogger.Logger); Database.Mapper = new PetaPocoMapper(); var scopeProvider = new ScopeProvider(dbFactory); dbFactory.ScopeProvider = scopeProvider; var dbContext = new DatabaseContext( scopeProvider, ProfilingLogger.Logger, SqlSyntaxProviders.CreateDefault(ProfilingLogger.Logger)); //initialize the DatabaseContext dbContext.Initialize(); //get the service context var serviceContext = CreateServiceContext(dbContext, scopeProvider); //set property and singleton from response ApplicationContext.Current = ApplicationContext = CreateApplicationContext(dbContext, serviceContext); InitializeApplicationEventsResolver(); InitializeResolvers(); InitializeModelMappers(); using (ProfilingLogger.DebugDuration <CoreBootManager>( string.Format("Executing {0} IApplicationEventHandler.OnApplicationInitialized", ApplicationEventsResolver.Current.ApplicationEventHandlers.Count()), "Finished executing IApplicationEventHandler.OnApplicationInitialized")) { //now we need to call the initialize methods ApplicationEventsResolver.Current.ApplicationEventHandlers .ForEach(x => { try { using (ProfilingLogger.DebugDuration <CoreBootManager>(string.Format("Executing {0} in ApplicationInitialized", x.GetType()))) { x.OnApplicationInitialized(UmbracoApplication, ApplicationContext); } } catch (Exception ex) { ProfilingLogger.Logger.Error <CoreBootManager>("An error occurred running OnApplicationInitialized for handler " + x.GetType(), ex); throw; } }); } _isInitialized = true; return(this); }
public static DatabaseContext GetDatabaseContext(IDatabaseFactory factory = null, ILogger logger = null, SqlSyntaxProviders sqlSyntaxProviers = null) { return(new DatabaseContext(factory ?? Mock.Of <IDatabaseFactory>(), logger ?? Mock.Of <ILogger>(), sqlSyntaxProviers ?? new SqlSyntaxProviders(new[] { Mock.Of <ISqlSyntaxProvider>() }))); }