From df291ea9a65e7af624af655e0d9af93ee7fa2c14 Mon Sep 17 00:00:00 2001 From: Alexandre Brandizzi Date: Fri, 24 Jul 2026 16:40:46 -0300 Subject: [PATCH] fix(architecture): abstract job run state access --- Api.SeaHavenIndustries/Program.cs | 3 +++ .../Implementation/WorkOrderOpsHealthService.cs | 13 +++---------- SeaHaven.Services/Interfaces/IServicePorts.cs | 13 +++++++++++++ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Api.SeaHavenIndustries/Program.cs b/Api.SeaHavenIndustries/Program.cs index d043c46..d88536f 100644 --- a/Api.SeaHavenIndustries/Program.cs +++ b/Api.SeaHavenIndustries/Program.cs @@ -13,6 +13,7 @@ using System.Text; using SeaHaven.DataServices.DependencyInjection; using SeaHaven.Services.DependencyInjection; using SeaHaven.Services.Implementation; +using SeaHaven.Services.Interfaces; var builder = WebApplication.CreateBuilder(args); ConfigurationManager configuration = builder.Configuration; @@ -83,6 +84,8 @@ builder.Services.Configure( builder.Services.Configure( builder.Configuration.GetSection(LegacyEndpointOptions.SectionName)); builder.Services.AddSingleton(); +builder.Services.AddSingleton( + sp => sp.GetRequiredService()); builder.Services.AddSingleton(sp => sp.GetRequiredService().State); builder.Services.AddScoped(); builder.Services.AddHostedService(); diff --git a/SeaHaven.Services/Implementation/WorkOrderOpsHealthService.cs b/SeaHaven.Services/Implementation/WorkOrderOpsHealthService.cs index 0b20f96..aa85017 100644 --- a/SeaHaven.Services/Implementation/WorkOrderOpsHealthService.cs +++ b/SeaHaven.Services/Implementation/WorkOrderOpsHealthService.cs @@ -8,12 +8,12 @@ namespace SeaHaven.Services.Implementation public class WorkOrderOpsHealthService : IWorkOrderOpsHealthService { private readonly IWorkOrderOpsHealthDataService _healthData; - private readonly WorkOrderJobRunStateAccessor _runState; + private readonly IWorkOrderJobRunStateAccessor _runState; private readonly WorkOrderOpsHealthOptions _options; public WorkOrderOpsHealthService( IWorkOrderOpsHealthDataService healthData, - WorkOrderJobRunStateAccessor runState, + IWorkOrderJobRunStateAccessor runState, IOptions options) { _healthData = healthData; @@ -58,16 +58,9 @@ namespace SeaHaven.Services.Implementation } /// Shared in-memory job run timestamps (API hosted services + ops health). - public class WorkOrderJobRunStateAccessor + public class WorkOrderJobRunStateAccessor : IWorkOrderJobRunStateAccessor { public WorkOrderJobRunState State { get; } = new(); } - public class WorkOrderJobRunState - { - public DateTime? LastWeekRolledRunUtc { get; set; } - public DateTime? LastPastDueCacheRunUtc { get; set; } - public string? LastWeekRolledError { get; set; } - public string? LastPastDueCacheError { get; set; } - } } diff --git a/SeaHaven.Services/Interfaces/IServicePorts.cs b/SeaHaven.Services/Interfaces/IServicePorts.cs index b159f3a..aae1383 100644 --- a/SeaHaven.Services/Interfaces/IServicePorts.cs +++ b/SeaHaven.Services/Interfaces/IServicePorts.cs @@ -2,6 +2,19 @@ using Microsoft.AspNetCore.Http; namespace SeaHaven.Services.Interfaces { + public interface IWorkOrderJobRunStateAccessor + { + WorkOrderJobRunState State { get; } + } + + public sealed class WorkOrderJobRunState + { + public DateTime? LastWeekRolledRunUtc { get; set; } + public DateTime? LastPastDueCacheRunUtc { get; set; } + public string? LastWeekRolledError { get; set; } + public string? LastPastDueCacheError { get; set; } + } + public interface IFileStoragePort { Task SaveFileAsync(IFormFile file);