CommunityToolkit.Mvvm.DependencyInjection Namespace
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Classes
Ioc |
A type that facilitates the use of the IServiceProvider type. The Ioc provides the ability to configure services in a singleton, thread-safe service provider instance, which can then be used to resolve service instances. The first step to use this feature is to declare some services, for instance:
Then the services configuration should then be done at startup, by calling the ConfigureServices(IServiceProvider) method and passing an IServiceProvider instance with the services to use. That instance can be from any library offering dependency injection functionality, such as Microsoft.Extensions.DependencyInjection. For instance, using that library, ConfigureServices(IServiceProvider) can be used as follows in this example:
Finally, you can use the Ioc instance (which implements IServiceProvider) to retrieve the service instances from anywhere in your application, by doing as follows:
|