CommunityToolkit.Mvvm8.1 IOC dependency injection control inversion (5)
CommunityToolkit.Mvvm8.1 IOC dependency injection control inversion (5) Navigation of this series of articles https://www.cnblogs.com/aierong/p/17300066.html https://github.com/aierong/WpfDemo (self-Demo address) I hope the knowledge mentioned can give you some hints, and welcome to communicate and correct. Author: aierongSource: https://www.cnblogs.com/aierong Description The CommunityToolkit.Mvvm package does not provide the ioc function, but the official recommendation is to use: Microsoft.Extensions.DependencyInjection uses IOC Install nuget:Microsoft.Extensions.DependencyInjection package Definition and implementation of interfaces and services public interface IBill { bool IsExistId ( string name ); string GetData ( string name ); } public class BillService : IBill { public string GetData ( string name ) { return string. Format( “name:{0}” , name ); } public bool IsExistId ( string name ) { return name == “qq”; } } App.xaml.cs registration public partial class App : Application { /// /// Gets the current instance in use /// public new static App Current => ( App ) Application. Current; /// /// Gets the instance to resolve application services. /// public IServiceProvider Services { get; } public App () { Services = ConfigureServices(); this. InitializeComponent(); } private static IServiceProvider ConfigureServices() { var services = new ServiceCollection(); // Register Services services.AddSingleton(); services.AddSingleton(); //services.AddSingleton(); // Register Viewmodels // Not every Viewmodels has to come…