protected virtual void InitApp() { Status = EntityAppStatus.Initializing; SetupLogFileWriters(); ActivationLog.WriteMessage("Initializing EntityApp {0}.====================================", this.AppName); this.AppEvents.OnInitializing(EntityAppInitStep.Initializing); //Check dependencies foreach (var mod in this.Modules) { var depList = mod.GetDependencies(); foreach (var dep in depList) { var ok = Modules.Any(m => dep.IsTypeOrSubType(m)); if (!ok) { ActivationLog.LogError($"Module {mod.Name} requires dependent module {dep} which is not included in the app."); } } } CheckActivationErrors(); //Build model var builder = new EntityModelBuilder(this); builder.BuildModel(); CheckActivationErrors(); //Notify modules that entity app is constructed foreach (var module in this.Modules) { module.Init(); } //init services; note that service might be registered more than once, under different interface var servList = this.GetAllServices().Distinct().ToList(); for (int i = 0; i < servList.Count; i++) { var service = servList[i]; var iServiceInit = service as IEntityServiceBase; if (iServiceInit != null) { iServiceInit.Init(this); } } //complete initialization this.AppEvents.OnInitializing(EntityAppInitStep.Initialized); foreach (var module in this.Modules) { module.AppInitComplete(); } builder.CheckErrors(); Status = EntityAppStatus.Initialized; ActivationLog.WriteMessage("App {0} initialized.", this.AppName); }
/// <summary>Initializes the entity app. </summary> /// <remarks>Call this method after you finished composing entity application of modules. /// The method is called automatically when you connect the application to the database /// with <c>ConnectTo()</c> extension method.</remarks> public virtual void Init() { if (Status != EntityAppStatus.Created) { return; } Status = EntityAppStatus.Initializing; SystemLog.Info("Initializing app {0}...", this.AppName); this.AppEvents.OnInitializing(EntityAppInitStep.Initializing); //Check dependencies foreach (var mod in this.Modules) { var depList = mod.GetDependencies(); foreach (var dep in depList) { var ok = Modules.Any(m => dep.IsTypeOrSubType(m)); if (!ok) { this.SystemLog.Error("Module {0} requires dependent module {1} which is not included in the app.", mod.GetType(), dep); } } } this.CheckActivationErrors(); // Init linked apps foreach (var linkedApp in LinkedApps) { linkedApp.Init(); } // create default services, possibly importing from LinkedApps CreateDefaultServices(); // Create log file writer if (!string.IsNullOrWhiteSpace(_logFilePath)) { _logFileWriter = new LogFileWriter(this, _logFilePath); } //Build model SystemLog.Info(" Building entity model...", this.AppName); var modelBuilder = new EntityModelBuilder(this); modelBuilder.BuildModel(); if (SystemLog.HasErrors) { var errors = SystemLog.GetAllAsText(); throw new StartupFailureException("Entity model build failed.", errors); } //Notify modules that entity app is constructed foreach (var module in this.Modules) { module.Init(); } //init services var servList = this.GetAllServices(); for (int i = 0; i < servList.Count; i++) { var service = servList[i]; var iServiceInit = service as IEntityService; if (iServiceInit != null) { iServiceInit.Init(this); } } //complete initialization this.AppEvents.OnInitializing(EntityAppInitStep.Initialized); foreach (var module in this.Modules) { module.AppInitComplete(); } CheckActivationErrors(); Status = EntityAppStatus.Initialized; SystemLog.Info(" App {0} initialized.", this.AppName); }
public static string LastFatalError; // error log sets this if it fails to persist error protected virtual void InitApp() { Util.Check(this.EntityClassProvider != null, "EntityApp.{0} may not be null. Use {1} method from Vita.Entities.Emit assembly to create provider instance.", nameof(EntityClassProvider), "Vita.Entities.Emit.EntityClassEmitter.CreateProvider()"); RegisterService <IEntityClassProvider>(EntityClassProvider); Status = EntityAppStatus.Initializing; CreateLogFileWriters(); ActivationLog.Info("Initializing EntityApp {0}.====================================", this.AppName); this.AppEvents.OnInitializing(EntityAppInitStep.Initializing); //Check dependencies foreach (var mod in this.Modules) { var depList = mod.GetDependencies(); foreach (var dep in depList) { var ok = Modules.Any(m => dep.IsTypeOrSubType(m)); if (!ok) { ActivationLog.Error("Module {0} requires dependent module {1} which is not included in the app.", mod.GetType(), dep); } } } ActivationLog.CheckErrors(); // Init linked apps foreach (var linkedApp in LinkedApps) { if (linkedApp.Status == EntityAppStatus.Created) { linkedApp.Init(); } } //Build model var builder = new EntityModelBuilder(this); builder.BuildModel(); ActivationLog.CheckErrors(); //Notify modules that entity app is constructed foreach (var module in this.Modules) { module.Init(); } //init services var servList = this.GetAllServices(); for (int i = 0; i < servList.Count; i++) { var service = servList[i]; var iServiceInit = service as IEntityServiceBase; if (iServiceInit != null) { iServiceInit.Init(this); } } //complete initialization this.AppEvents.OnInitializing(EntityAppInitStep.Initialized); foreach (var module in this.Modules) { module.AppInitComplete(); } builder.CheckErrors(); Status = EntityAppStatus.Initialized; ActivationLog.Info("App {0} initialized.", this.AppName); }