refactor: address code smells (run-dir helper, App DI injection)
- TaskRunner: extract worktree-vs-sandbox selection into PrepareRunDirectoryAsync so RunAsync reads linearly (a small helper, not a Strategy pattern — overkill for a two-way branch). - App: drop the public static ServiceProvider locator; inject the provider via constructor through AppBuilder.Configure(() => new App(services)). Parameterless ctor + BuildAvaloniaApp() retained for the XAML designer. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Markup.Xaml;
|
||||
@@ -10,7 +11,12 @@ namespace ClaudeDo.App;
|
||||
|
||||
public partial class App : Application
|
||||
{
|
||||
public static ServiceProvider Services { get; set; } = null!;
|
||||
private readonly IServiceProvider? _services;
|
||||
|
||||
// Parameterless ctor is required by the XAML previewer / designer.
|
||||
public App() { }
|
||||
|
||||
public App(IServiceProvider services) => _services = services;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -21,16 +27,19 @@ public partial class App : Application
|
||||
{
|
||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
var services = _services
|
||||
?? throw new InvalidOperationException("App was constructed without a service provider.");
|
||||
|
||||
FocusClearing.Install();
|
||||
|
||||
desktop.MainWindow = new MainWindow
|
||||
{
|
||||
DataContext = Services.GetRequiredService<IslandsShellViewModel>(),
|
||||
DataContext = services.GetRequiredService<IslandsShellViewModel>(),
|
||||
};
|
||||
|
||||
// Kick off the SignalR retry loop — reconnects indefinitely if the worker
|
||||
// is not up yet, or goes down and comes back.
|
||||
_ = Services.GetRequiredService<WorkerClient>().StartAsync();
|
||||
_ = services.GetRequiredService<WorkerClient>().StartAsync();
|
||||
}
|
||||
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
|
||||
Reference in New Issue
Block a user