Introducing Dependency Injection and Platform-Specific Services
In the last chapter, we introduced navigation and Shell in .NET Multi-platform App UI (.NET MAUI), and we completed the navigation design of our app. We improved two interfaces, IDataStore
and IUserService
, to separate the model from the view and view model. In the current code, we used the DependencyService
class to decouple the interface implementations. In this chapter, we will refine our design using dependency injection (DI) to replace the DependencyService
class. There is a built-in service to support DI in .NET MAUI. With the help of DI, we can refine our design and decouple the dependencies in a more elegant way.
We will cover the following topics in this chapter:
- A quick review of design principles
- Using DI
- Connecting to the database
DI is a technique to realize the design principle of dependency inversion or Dependency Inversion Principle (DIP). DIP is one of the SOLID design principles...