.NET MAUI › Migration from Xamarin.Forms

How do you replace DependencyService with MAUI dependency injection?

Intermediate

Answer

Register the interface/implementation in MauiProgram's Services and inject via constructors instead of calling DependencyService.Get<T>(). This is testable and explicit. For gradual migration you can keep a temporary service-locator shim, but the goal is constructor injection throughout.
// Old
var svc = DependencyService.Get<IPhotoService>();
// New
builder.Services.AddSingleton<IPhotoService, PhotoService>();
public MyViewModel(IPhotoService svc) { _svc = svc; }
Real-world example Platform photo access moves from DependencyService lookups to a normally injected IPhotoService.

Common follow-ups: Why is DI preferable? | Can you migrate incrementally?