Program.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. public static async Task Main(string[] args) {
  11. var builder = WebAssemblyHostBuilder.CreateDefault(args);
  12. builder.RootComponents.Add<App>("#app");
  13. builder.RootComponents.Add<HeadOutlet>("head::after");
  14. IServiceCollection services = builder.Services;
  15. builder.Services.AddScoped(sp => {
  16. NavigationManager nav = sp.GetRequiredService<NavigationManager>();
  17. return new HttpClient {
  18. BaseAddress = new Uri(nav.BaseUri)
  19. };
  20. });
  21. builder.Services.AddScoped<ITextFileStore, WasmTextFileStore>();
  22. var resources = new ResourceCollection();
  23. builder.Services.AddSingleton(resources);
  24. var yamlDir = builder.Configuration.GetValue<string>("RPK_YAML_DIR") ?? "config";
  25. var yamlFilePath = $"{yamlDir}/config.yaml";
  26. builder.Services.AddScoped<RackPeekConfigMigrationDeserializer>();
  27. builder.Services.AddScoped<IResourceYamlMigrationService, ResourceYamlMigrationService>();
  28. builder.Services.AddScoped<IResourceCollection>(sp =>
  29. new YamlResourceCollection(
  30. yamlFilePath,
  31. sp.GetRequiredService<ITextFileStore>(),
  32. sp.GetRequiredService<ResourceCollection>(),
  33. sp.GetRequiredService<IResourceYamlMigrationService>()));
  34. builder.Services.AddYamlRepos();
  35. builder.Services.AddCommands();
  36. builder.Services.AddScoped<IConsoleEmulator, ConsoleEmulator>();
  37. builder.Services.AddUseCases();
  38. builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
  39. await builder.Build().RunAsync();
  40. }
  41. }