This commit is contained in:
Jonathan Jenne
2023-11-30 14:00:30 +01:00
parent 1b88a6cff7
commit c2de72be74
25 changed files with 875 additions and 148 deletions

View File

@@ -7,6 +7,18 @@ namespace EnvelopeGenerator.Web.Services
{
public MSSQLServer MSSQL { get; set; }
public State State { get; set; }
public class ServiceContainer
{
public ActionService actionService;
public ServiceContainer(State state)
{
actionService = new(state);
}
}
public class ModelContainer
{
public EnvelopeModel envelopeModel;
@@ -31,6 +43,7 @@ namespace EnvelopeGenerator.Web.Services
}
}
public readonly ModelContainer? Models;
public readonly ServiceContainer? Services;
public DatabaseService(IConfiguration Config, LoggingService Logging) : base(Config, Logging)
{
@@ -41,19 +54,14 @@ namespace EnvelopeGenerator.Web.Services
if (MSSQL.DBInitialized == true)
{
logger.Debug("MSSQL Connection: [{0}]", MSSQL.CurrentConnectionString);
// There is a circular dependency between state and models
// All models need a state object, including the config Model
// The state object needs to be filled with the DbConfig property,
// which is obtained by the config Model.
// So first, the config model is initialized with an incomplete state object,
// then all the other models with the DbConfig property filled.
logger.Debug("MSSQL Connection established: [{0}]", MSSQL.MaskedConnectionString);
var state = GetState();
var configModel = new ConfigModel(state);
state.DbConfig = configModel.LoadConfiguration();
Models = new(state);
Models = new(state);
Services = new(state);
State = state;
}
else
{
@@ -61,13 +69,31 @@ namespace EnvelopeGenerator.Web.Services
}
}
public State GetState()
/// <summary>
/// There is a circular dependency between state and models
/// All models need a state object, including the config Model
/// The state object needs to be filled with the DbConfig property,
/// which is obtained by the config Model.
/// So first, the config model is initialized with an incomplete state object,
/// then all the other models with the DbConfig property filled.
/// </summary>
private State GetState()
{
var state = GetInitialState();
var configModel = new ConfigModel(state);
state.DbConfig = configModel.LoadConfiguration();
return state;
}
private State GetInitialState()
{
return new State
{
Database = MSSQL,
LogConfig = logConfig,
UserId = 2 // TODO
UserId = 0,
DbConfig = null
};
}
}