Skip to content

Commit

Permalink
Added AvaloniaLocator.GetRequiredService.
Browse files Browse the repository at this point in the history
  • Loading branch information
grokys committed Aug 3, 2022
1 parent 50f02de commit fcada17
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Avalonia.Base/AvaloniaLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ public static class LocatorExtensions
{
return (T?) resolver.GetService(typeof (T));
}

public static object GetRequiredService(this IAvaloniaDependencyResolver resolver, Type t)
{
return resolver.GetService(t) ?? throw new InvalidOperationException($"Unable to locate '{t}'.");
}

public static T GetRequiredService<T>(this IAvaloniaDependencyResolver resolver)
{
return (T?)resolver.GetService(typeof(T)) ?? throw new InvalidOperationException($"Unable to locate '{typeof(T)}'.");
}
}
}

0 comments on commit fcada17

Please sign in to comment.