forked from amkovkov/GranuSightSoftware2
feat: create di helper and update appsettings
This commit is contained in:
+14
-42
@@ -1,8 +1,6 @@
|
||||
using System.Data;
|
||||
using GSS2.Core.Analysis.AmineContent.Database;
|
||||
using GSS2.Core.Hardware;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.IdentityModel.Protocols.Configuration;
|
||||
using GSS2.Core;
|
||||
using GSS2.Core.Analysis.AmineContent.Database;
|
||||
|
||||
namespace GSS2.Test;
|
||||
|
||||
@@ -12,44 +10,13 @@ public class Program
|
||||
{
|
||||
var builder = Host.CreateApplicationBuilder(args);
|
||||
|
||||
builder.Services.AddDbContext<AmineContentCalibrationContext>(
|
||||
options =>
|
||||
{
|
||||
var databasePath = builder.Configuration.GetConnectionString("AmineContentCalibrationDatabasePath");
|
||||
options.UseSqlite($"Data Source={databasePath}");
|
||||
},
|
||||
ServiceLifetime.Singleton
|
||||
);
|
||||
builder.Services.AddSingleton<LightsService>(
|
||||
serviceProvider =>
|
||||
{
|
||||
var configuration = serviceProvider.GetService<IConfiguration>();
|
||||
if (configuration is null)
|
||||
throw new Exception("Cannot get configuration");
|
||||
var serviceConfiguration = configuration.GetSection("Hardware:Lights").Get<LightsService.LightsServiceConfiguration>();
|
||||
if (serviceConfiguration is null)
|
||||
throw new InvalidConfigurationException("Cannot get configuration (Hardware:Lights)");
|
||||
var logger = serviceProvider.GetService<ILogger<LightsService>>();
|
||||
if (logger is null)
|
||||
throw new Exception("Cannot get logger");
|
||||
return new LightsService(logger, serviceConfiguration);
|
||||
}
|
||||
);
|
||||
builder.Services.AddSingleton<TemperatureHumidityService>(
|
||||
serviceProvider =>
|
||||
{
|
||||
var configuration = serviceProvider.GetService<IConfiguration>();
|
||||
if (configuration is null)
|
||||
throw new Exception("Cannot get configuration");
|
||||
var serviceConfiguration = configuration.GetSection("Hardware:TemperatureHumidity").Get<TemperatureHumidityService.TemperatureHumidityServiceConfiguration>();
|
||||
if (serviceConfiguration is null)
|
||||
throw new InvalidConfigurationException("Cannot get configuration (Hardware:TemperatureHumidity)");
|
||||
var logger = serviceProvider.GetService<ILogger<TemperatureHumidityService>>();
|
||||
if (logger is null)
|
||||
throw new Exception("Cannot get logger");
|
||||
return new TemperatureHumidityService(logger, serviceConfiguration);
|
||||
}
|
||||
);
|
||||
builder.Services.AddAmineContentCalibrationContext(builder.Configuration);
|
||||
builder.Services.AddAmineContentResultsContext(builder.Configuration);
|
||||
|
||||
builder.Services.AddLightsService("Hardware:Lights");
|
||||
builder.Services.AddTemperatureHumidityService("Hardware:TemperatureHumidity");
|
||||
builder.Services.AddIlluminatorService("Hardware:Illuminator");
|
||||
builder.Services.AddCameraService("Hardware:Camera");
|
||||
|
||||
builder.Services.AddHostedService<Worker>();
|
||||
|
||||
@@ -60,6 +27,11 @@ public class Program
|
||||
var context = scope.ServiceProvider.GetRequiredService<AmineContentCalibrationContext>();
|
||||
context.Database.Migrate();
|
||||
}
|
||||
using (var scope = host.Services.CreateScope())
|
||||
{
|
||||
var context = scope.ServiceProvider.GetRequiredService<AmineContentResultsContext>();
|
||||
context.Database.Migrate();
|
||||
}
|
||||
|
||||
host.Run();
|
||||
}
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"AmineContentCalibrationDatabasePath": "AmineContentCalibration.db"
|
||||
"AmineContentCalibrationDatabasePath": "AmineContentCalibration.db",
|
||||
"AmineContentResultsDatabasePath": "AmineContentResults.db"
|
||||
},
|
||||
"Hardware": {
|
||||
"Illuminator": {
|
||||
@@ -22,6 +23,13 @@
|
||||
"MaxUv254PwmDuty": 1.0,
|
||||
"MaxUv365PwmDuty": 1.0
|
||||
},
|
||||
"Camera": {
|
||||
"ViewFinderWidth": 1920,
|
||||
"ViewFinderHeight": 1080,
|
||||
"ViewFinderFps": 30,
|
||||
"ImageCaptureWidth": 4056,
|
||||
"ImageCaptureHeight": 3080
|
||||
},
|
||||
"TemperatureHumidity": {
|
||||
"Bus": 6,
|
||||
"Address": 69
|
||||
|
||||
Reference in New Issue
Block a user