Program.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using Microsoft.AspNetCore.Hosting.StaticWebAssets;
  2. using RackPeek.Domain;
  3. using RackPeek.Domain.Persistence;
  4. using RackPeek.Domain.Persistence.Yaml;
  5. using RackPeek.Domain.Resources;
  6. using RackPeek.Domain.Resources.Hardware;
  7. using RackPeek.Domain.Resources.Services;
  8. using RackPeek.Domain.Resources.SystemResources;
  9. using RackPeek.Web.Components;
  10. using RackPeek.Yaml;
  11. using Shared.Rcl;
  12. namespace RackPeek.Web;
  13. public class Program
  14. {
  15. public static async Task Main(string[] args)
  16. {
  17. var builder = WebApplication.CreateBuilder(args);
  18. StaticWebAssetsLoader.UseStaticWebAssets(
  19. builder.Environment,
  20. builder.Configuration
  21. );
  22. var yamlDir = "./config";
  23. var basePath = Directory.GetCurrentDirectory();
  24. // Resolve yamlDir as relative to basePath
  25. var yamlPath = Path.IsPathRooted(yamlDir)
  26. ? yamlDir
  27. : Path.Combine(basePath, yamlDir);
  28. if (!Directory.Exists(yamlPath))
  29. throw new DirectoryNotFoundException(
  30. $"YAML directory not found: {yamlPath}"
  31. );
  32. var collection = new YamlResourceCollection(Path.Combine(yamlDir, "config.yaml"), new PhysicalTextFileStore());
  33. await collection.LoadAsync();
  34. // Infrastructure
  35. builder.Services.AddSingleton<IHardwareRepository>(_ => new YamlHardwareRepository(collection));
  36. builder.Services.AddSingleton<ISystemRepository>(_ => new YamlSystemRepository(collection));
  37. builder.Services.AddSingleton<IServiceRepository>(_ => new YamlServiceRepository(collection));
  38. builder.Services.AddSingleton<IResourceRepository>(_ => new YamlResourceRepository(collection));
  39. builder.Services.AddUseCases();
  40. // Add services to the container.
  41. builder.Services.AddRazorComponents()
  42. .AddInteractiveServerComponents();
  43. var app = builder.Build();
  44. // Configure the HTTP request pipeline.
  45. if (!app.Environment.IsDevelopment())
  46. {
  47. app.UseExceptionHandler("/Error");
  48. // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
  49. app.UseHsts();
  50. }
  51. app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true);
  52. app.UseHttpsRedirection();
  53. app.UseStaticFiles();
  54. app.UseAntiforgery();
  55. app.MapStaticAssets();
  56. app.MapRazorComponents<App>()
  57. .AddInteractiveServerRenderMode();
  58. await app.RunAsync();
  59. }
  60. }