DEV Community

iainrough
iainrough

Posted on

Maui Tip - Resolve a dependancy in MauiProgram.cs

Need to resolve a dependency in CreateMauiApp() method in MauiProgram.cs?

If you google around you find you need to get an instance of IServiceProvider, this can be achived using the snippet bellow


var serviceProvider = builder.Services.BuildServiceProvider();

var myService = serviceProvider.GetService<MyService>()

Enter fullscreen mode Exit fullscreen mode

MauiProgram.cs

Top comments (0)