79565320

Date: 2025-04-09 21:05:38
Score: 0.5
Natty:
Report link

Another approach I used with my project was the Avalonia.Hosting library. In my Program.cs, I have

builder.Services
    .AddSerilog()
    .AddTransient<IUpdaterSettings, UpdaterSettings>()
    .AddTransient<VersionPoster>()
    .AddTransient<UpdateChecker>()
    .AddTransient<DownloadManager>()
    .AddSingleton<UpdateService>()
    .AddTransient<NetworkScannerPageVm>()
    .AddSingleton<AboutPageVm>()
    .AddTransient<MainWindowVm>()
    .AddTransient<NetworkScannerPage>()
    .AddTransient<AboutPage>()
    .AddTransient<HomePage>()
    .AddTransient<MainWindow>()
    .AddAvaloniauiDesktopApplication<App>(ConfigureAvaloniaAppBuilder);

That last line being the magic sauce.

However, I'd like to use Scrutor to dynamically register my views with the DI container, and it isn't picking up the public partial classes for some reason. I find @kekekeks advice to use a view locator instead of DI for the views interesting, and I may end up going that route instead.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @kekekeks
  • Low reputation (0.5):
Posted by: Stanley G.