using System;
using System.Windows;
using ExcelHelper.Services;
using ExcelHelper.Utils;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace ExcelHelper;
///
/// App.xaml 的交互逻辑
///
public partial class App : Application
{
public static App AppHost;
private readonly IHost _host = Host.CreateDefaultBuilder()
.AddViewAndViewModel()
.ConfigureServices((context, services) =>
{
services.AddHostedService();
services.AddSingleton();
})
.Build();
protected override void OnStartup(StartupEventArgs e)
{
AppHost = this;
base.OnStartup(e);
// 初始化AppHost
_host.Start();
}
public T Get()
{
return _host.Services.GetService();
}
public object Get(Type type)
{
return _host.Services.GetService(type);
}
}