Browse Source

Added AvaloniaLocator.GetRequiredService.

pull/8699/head
Steven Kirk 4 years ago
parent
commit
fcada170af
  1. 10
      src/Avalonia.Base/AvaloniaLocator.cs

10
src/Avalonia.Base/AvaloniaLocator.cs

@ -125,6 +125,16 @@ namespace Avalonia
{
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)}'.");
}
}
}

Loading…
Cancel
Save