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