static IServiceProvider CreateCompatServiceProvider() { var collection = new MauiServiceCollection(); collection.AddSingleton <ILoggerFactory, FallbackLoggerFactory>(); collection.AddSingleton <IFontRegistrar>(svc => new FontRegistrar(_embeddedFontLoader, svc.CreateLogger <FontRegistrar>())); collection.AddSingleton <IFontManager>(svc => new FontManager(svc.GetRequiredService <IFontRegistrar>(), svc.CreateLogger <FontManager>())); var provider = new MauiServiceProvider(collection, false); return(provider); }
public void GetRequiredServiceRetrievesService() { HandlerStub handlerStub = new HandlerStub(); var collection = new MauiServiceCollection(); collection.TryAddSingleton <IMauiHandlersServiceProvider>(new MauiHandlersServiceProvider(null)); collection.TryAddSingleton <IFooService, FooService>(); var provider = new MauiServiceProvider(collection, false); handlerStub.SetMauiContext(new HandlersContextStub(provider)); Assert.NotNull(handlerStub.MauiContext); Assert.NotNull(handlerStub.MauiContext.Services); var foo = handlerStub.GetRequiredService <IFooService>(); Assert.IsType <FooService>(foo); }