Skip to content

Commit

Permalink
Fixing client not implementable error in Avalonia template
Browse files Browse the repository at this point in the history
  • Loading branch information
Keboo committed Oct 13, 2024
1 parent 1dfccb5 commit 1ad9cb8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Templates.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<PackageType>Template</PackageType>
<PackageVersion>1.7.2</PackageVersion>
<PackageVersion>1.7.3</PackageVersion>
<PackageId>Keboo.Dotnet.Templates</PackageId>
<Title>Keboo's .NET Templates</Title>
<Authors>Keboo</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static void AddServices(this IServiceCollection services)
private static void AddAvaloniaServices(this IServiceCollection services)
{
services.AddSingleton<IDispatcher>(_ => Dispatcher.UIThread);
services.AddSingleton(_ => Application.Current?.ApplicationLifetime ?? NoopApplicationLifetime.Instance);
services.AddSingleton(_ => Application.Current?.ApplicationLifetime ?? throw new InvalidOperationException("No application lifetime is set"));

services.AddSingleton(sp =>
sp.GetRequiredService<IApplicationLifetime>() switch
Expand Down Expand Up @@ -49,15 +49,4 @@ private static void AddView<TView, TViewModel>(this IServiceCollection services)
services.AddTransient<TViewModel>();
services.AddTransient<TView>();
}

private sealed class NoopApplicationLifetime : IDisposable, IApplicationLifetime
{
private static readonly Lazy<NoopApplicationLifetime> _instance = new(() => new NoopApplicationLifetime());
public static IApplicationLifetime Instance => _instance.Value;

private NoopApplicationLifetime()
{ }

public void Dispose() { }
}
}

0 comments on commit 1ad9cb8

Please sign in to comment.