Program.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using Microsoft.AspNetCore.Components;
  2. using Microsoft.AspNetCore.Components.Web;
  3. using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
  4. using RackPeek.Domain;
  5. using RackPeek.Domain.Persistence;
  6. using RackPeek.Domain.Persistence.Yaml;
  7. using Shared.Rcl;
  8. namespace RackPeek.Web.Viewer;
  9. public class Program
  10. {
  11. public static async Task Main(string[] args)
  12. {
  13. var builder = WebAssemblyHostBuilder.CreateDefault(args);
  14. builder.RootComponents.Add<App>("#app");
  15. builder.RootComponents.Add<HeadOutlet>("head::after");
  16. IServiceCollection services = builder.Services;
  17. builder.Services.AddScoped(sp =>
  18. {
  19. NavigationManager nav = sp.GetRequiredService<NavigationManager>();
  20. return new HttpClient
  21. {
  22. BaseAddress = new Uri(nav.BaseUri)
  23. };
  24. });
  25. builder.Services.AddScoped<ITextFileStore, WasmTextFileStore>();
  26. var resources = new ResourceCollection();
  27. builder.Services.AddSingleton(resources);
  28. var yamlDir = builder.Configuration.GetValue<string>("RPK_YAML_DIR") ?? "config";
  29. var yamlFilePath = $"{yamlDir}/config.yaml";
  30. builder.Services.AddScoped<RackPeekConfigMigrationDeserializer>();
  31. builder.Services.AddScoped<IResourceYamlMigrationService, ResourceYamlMigrationService>();
  32. builder.Services.AddScoped<IResourceCollection>(sp =>
  33. new YamlResourceCollection(
  34. yamlFilePath,
  35. sp.GetRequiredService<ITextFileStore>(),
  36. sp.GetRequiredService<ResourceCollection>(),
  37. sp.GetRequiredService<IResourceYamlMigrationService>()));
  38. builder.Services.AddYamlRepos();
  39. builder.Services.AddCommands();
  40. builder.Services.AddScoped<IConsoleEmulator, ConsoleEmulator>();
  41. builder.Services.AddUseCases();
  42. builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
  43. await builder.Build().RunAsync();
  44. }
  45. }