NucuCar/NucuCar.Sensors/Program.cs

49 lines
2.2 KiB
C#
Raw Normal View History

using Microsoft.AspNetCore.Hosting;
2019-11-09 13:34:49 +00:00
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
2020-08-01 15:07:13 +00:00
using NucuCar.Sensors.Abstractions;
using NucuCar.Sensors.Grpc;
using NucuCar.Sensors.Modules.Environment;
using NucuCar.Sensors.Modules.Health;
using NucuCar.Sensors.Modules.Heartbeat;
using NucuCar.Sensors.Modules.PMS5003;
using NucuCar.Telemetry;
2019-11-09 13:34:49 +00:00
namespace NucuCar.Sensors
2019-11-09 13:34:49 +00:00
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
2019-11-09 13:34:49 +00:00
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.Configure<TelemetryConfig>(hostContext.Configuration.GetSection("Telemetry"));
services.Configure<Bme680Config>(hostContext.Configuration.GetSection("EnvironmentSensor"));
2019-12-29 12:10:58 +00:00
services.Configure<CpuTempConfig>(hostContext.Configuration.GetSection("HealthSensor"));
services.Configure<HeartbeatConfig>(hostContext.Configuration.GetSection("HeartbeatSensor"));
services.Configure<Pms5003Config>(hostContext.Configuration.GetSection("Pms5003Sensor"));
// Singletons
services.AddSingleton<Telemetry.Telemetry>();
2019-11-30 16:55:55 +00:00
services.AddSingleton<ISensor<Bme680Sensor>, Bme680Sensor>();
services.AddSingleton<ISensor<CpuTempSensor>, CpuTempSensor>();
services.AddSingleton<ISensor<HeartbeatSensor>, HeartbeatSensor>();
services.AddSingleton<ISensor<Pms5003Sensor>, Pms5003Sensor>();
// Workers
// Telemetry
services.AddHostedService<TelemetryWorker>();
// Sensors
services.AddHostedService<Bme680Worker>();
services.AddHostedService<CpuTempWorker>();
services.AddHostedService<HeartbeatWorker>();
services.AddHostedService<Pms5003Worker>();
})
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<GrpcStartup>(); });
2019-11-09 13:34:49 +00:00
}
}