diff --git a/src/RolandK.AvaloniaExtensions.DependencyInjection.Tests/DependencyInjectionTests.cs b/src/RolandK.AvaloniaExtensions.DependencyInjection.Tests/DependencyInjectionTests.cs
index 0bfe18b..d651a40 100644
--- a/src/RolandK.AvaloniaExtensions.DependencyInjection.Tests/DependencyInjectionTests.cs
+++ b/src/RolandK.AvaloniaExtensions.DependencyInjection.Tests/DependencyInjectionTests.cs
@@ -142,6 +142,20 @@ public Task Create_Control_and_get_ServiceProvider_from_it()
});
}
+ [Fact]
+ public Task Get_ServiceProvider_from_Application()
+ {
+ return UnitTestApplication.RunInApplicationContextAsync(() =>
+ {
+ // Act
+ var serviceProvider = Application.Current?.GetServiceProvider();
+
+ // Assert
+ Assert.NotNull(serviceProvider);
+ Assert.NotNull(serviceProvider.GetService(typeof(IDummyService)));
+ });
+ }
+
//*************************************************************************
//*************************************************************************
//*************************************************************************
diff --git a/src/RolandK.AvaloniaExtensions.DependencyInjection/ControlExtensions.cs b/src/RolandK.AvaloniaExtensions.DependencyInjection/IResourceHostExtensions.cs
similarity index 83%
rename from src/RolandK.AvaloniaExtensions.DependencyInjection/ControlExtensions.cs
rename to src/RolandK.AvaloniaExtensions.DependencyInjection/IResourceHostExtensions.cs
index b1976c0..8dba4f0 100644
--- a/src/RolandK.AvaloniaExtensions.DependencyInjection/ControlExtensions.cs
+++ b/src/RolandK.AvaloniaExtensions.DependencyInjection/IResourceHostExtensions.cs
@@ -1,15 +1,14 @@
-using Avalonia;
using Avalonia.Controls;
namespace RolandK.AvaloniaExtensions.DependencyInjection;
-public static class ControlExtensions
+public static class IResourceHostExtensions
{
///
/// Gets the for this application.
/// Returns null, if the could not be found.
///
- public static IServiceProvider? TryGetServiceProvider(this StyledElement control)
+ public static IServiceProvider? TryGetServiceProvider(this IResourceHost control)
{
if(control.TryFindResource(DependencyInjectionConstants.SERVICE_PROVIDER_RESOURCE_KEY, out var resource) &&
resource is IServiceProvider serviceProvider)
@@ -23,7 +22,7 @@ public static class ControlExtensions
/// Gets the for this application.
///
/// could not be found
- public static IServiceProvider GetServiceProvider(this StyledElement control)
+ public static IServiceProvider GetServiceProvider(this IResourceHost control)
{
var serviceProvider = TryGetServiceProvider(control);
if (serviceProvider == null)
@@ -33,4 +32,4 @@ public static IServiceProvider GetServiceProvider(this StyledElement control)
}
return serviceProvider;
}
-}
+}
\ No newline at end of file