Program.cs 2.1 KB

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