Program.cs 2.4 KB

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