Created
February 28, 2024 11:23
-
-
Save jonathanMelly/95a43f294015dc3560f253fcfc13f9f7 to your computer and use it in GitHub Desktop.
maui service provider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace WeatherTwentyOne; | |
courtesy of : https://github.com/davidortinau/WeatherTwentyOne/blob/main/src/WeatherTwentyOne/Services/ServiceExtensions.cs | |
public static class ServiceProvider | |
{ | |
public static TService GetService<TService>() | |
=> Current.GetService<TService>(); | |
public static IServiceProvider Current | |
=> | |
#if WINDOWS10_0_17763_0_OR_GREATER | |
MauiWinUIApplication.Current.Services; | |
#elif ANDROID | |
MauiApplication.Current.Services; | |
#elif IOS || MACCATALYST | |
MauiUIApplicationDelegate.Current.Services; | |
#else | |
null; | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Or:
MauiProgram.Services.GetServices().First().CreateLogger("bob").LogDebug("hello debug");
var built = builder.Build();
Services = built.Services;