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