Alle Entitäten wurden mit Attributen erstellt und zu EFCore DBContex hinzugefügt.

This commit is contained in:
Developer 02
2024-04-02 14:53:25 +02:00
parent 6fc210132d
commit b65766ce24
30 changed files with 772 additions and 269 deletions

View File

@@ -1,14 +1,16 @@
using DigitalData.Modules.Database;
using DigitalData.Modules.Logging;
using EnvelopeGenerator.Common;
namespace EnvelopeGenerator.Web.Services
{
public class DatabaseService: BaseService
public class DatabaseService
{
public MSSQLServer MSSQL { get; set; }
public IConfiguration Config { get; set; }
public State State { get; set; }
ILogger<DatabaseService> _logger;
public State? State { get; set; }
public class ServiceContainer
{
@@ -48,62 +50,43 @@ namespace EnvelopeGenerator.Web.Services
public readonly ModelContainer? Models;
public readonly ServiceContainer? Services;
public DatabaseService(IConfiguration pConfig, LoggingService pLogging) : base(pConfig, pLogging)
public DatabaseService(ILogger<DatabaseService> logger, IConfiguration config)
{
logger = pLogging.LogConfig.GetLogger();
Config = pConfig;
LogConfig logConfig = new LogConfig(LogConfig.PathType.CustomPath, config["Config:LogPath"], null, "Digital Data", "ECM.EnvelopeGenerator.Web");
_logger = logger;
logger.Debug("Establishing MSSQL Database connection..");
MSSQL = new MSSQLServer(logConfig, pConfig["Config:ConnectionString"]);
_logger.LogInformation("Establishing MSSQL Database connection..");
MSSQL = new MSSQLServer(logConfig, config["Config:ConnectionString"]);
if (MSSQL.DBInitialized == true)
{
logger.Debug("MSSQL Connection established: [{0}]", MSSQL.MaskedConnectionString);
var state = GetState();
_logger.LogInformation("MSSQL Connection established: [{0}]", MSSQL.MaskedConnectionString);
Models = new(state);
Services = new(state);
/// <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>
State = new State
{
Database = MSSQL,
LogConfig = logConfig,
UserId = 0,
DbConfig = null
};
var configModel = new ConfigModel(State);
State.DbConfig = configModel.LoadConfiguration();
State = state;
Models = new(State);
Services = new(State);
}
else
{
logger.Error("Connection could not be established!");
_logger.LogInformation("Connection could not be established!");
}
}
public string? GetAppSetting(string key)
{
return Config[key];
}
/// <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 = 0,
DbConfig = null
};
}
}
}