引入:using Microsoft.Extensions.DependencyInjection;DI容器
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace MedicalRecordSelfTerminal.WpfApp
{
///
/// Interaction logic for App.xaml
///
public partial class App : Application
{
public App()
{
//组件注入
Services = ConfigureServices();
InitializeComponent();
}
///
/// 设置当前正在使用的App实例
///
public new static App Current => (App)Application.Current;
///
/// 定义服务通道
///
public IServiceProvider Services { get; }
///
/// 需要注入的组件
///
///
private static IServiceProvider ConfigureServices()
{
var services = new ServiceCollection();
//services.AddTransient
//services.AddTransient
//services.AddSingleton
return services.BuildServiceProvider();
}
}
}