Registering, resolving, and injecting services
.NET MAUI comes with built-in support for DI. It has been designed with DI in mind, which allows for easier configuration and management of services that your application relies on. By providing out-of-the-box support for DI, .NET MAUI enables developers to leverage the concept of DI and IoC to make their code more maintainable and more loosely coupled. As the MVVM pattern benefits tremendously from DI and IoC, it shows again that MVVM and .NET MAUI are a perfect match!
The Microsoft.Extensions.DependencyInjection
namespace is where .NET MAUI gets its default implementation for DI. However, it’s important to note that .NET MAUI is DI container agnostic, which means you’re not limited to the default. If you prefer a third-party DI container, you’re free to replace the default with your preferred choice. Let’s see how we can register services using .NET MAUI’s default DI implementation.