Implementing DI
DI is a technique that can be utilized in .NET MAUI. Although not a novel concept, it has been extensively employed in backend frameworks like ASP.NET Core and the Java Spring Framework. DI facilitates dependency inversion (DIP) by decoupling an object’s usage from its creation, eliminating the need for direct reliance on the object. In our app, once we have separated the IDataStore
interface implementation, we can commence with a mock implementation and subsequently replace it with the actual implementation.
In .NET MAUI, the Microsoft.Extensions.DependencyInjection
service, which we will refer to as MS.DI throughout this chapter, is readily available for us to utilize as a built-in feature.
In the realm of .NET, numerous DI containers are available besides MS.DI. Some of these alternatives, such as the Autofac DI container and the Simple Injector DI container, offer enhanced power and flexibility compared to MS.DI. At this point, one may wonder why...