Co-authored-by: Michael Hawker MSFT (XAML Llama) <24302614+michael-hawker@users.noreply.github.com>
This commit is contained in:
Sergio Pedri 2020-11-12 00:54:37 +01:00 коммит произвёл GitHub
Родитель 69f5a39ad0
Коммит e2851730cb
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 1 добавлений и 1 удалений

Просмотреть файл

@ -9,7 +9,7 @@ dev_langs:
# Ioc ([Inversion of control](https://en.wikipedia.org/wiki/Inversion_of_control))
A common pattern that can be used to increase modularity in the codebase of an application using the MVVM pattern is to use some form of inversion of control. One of the most common solution in particular is to use dependency injection, which consists in creating a number of services that are injected into backend classes (ie. passed as parameters to the viewmodel constructors) - this allows code using these services not to rely on implementation details of these services, and it also makes it easy to swap the concrete implementations of these services. This pattern also makes it easy to make platform-specific features available to backend code, by abstracting them through a service which is then injected where needed.
Inversion of Control is a common pattern that can be used to increase modularity in the codebase of an application when using the MVVM pattern. A frequently used way to enable this is to use _dependency injection_ (DI), which consists of creating a number of services that are injected into backend classes (i.e. passed as parameters to the viewmodel constructors). Doing this allows code using these services not to rely on the implementation details of these services, and it also makes it easy to swap the concrete implementations of these services. This pattern also makes it easy to make platform-specific features available to backend code, by abstracting them through a service which is then injected where needed. Since services are then isolated from where they are used, they become more testable as well.
The MVVM Toolkit doesn't provide built-in APIs to facilitate the usage of this pattern, as there already exist dedicated libraries specifically for this such as the `Microsoft.Extensions.DependencyInjection` package, which provides a fully featured and powerful DI set of APIs, and acts as an easy to setup and use `IServiceProvider`. The following guide will refer to this library and provide a series of examples of how to integrate it into applications using the MVVM pattern.