using Admin.Core.Wpf.View;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Windows;
using Microsoft.Extensions.Configuration;
using System.IO;
using Microsoft.Extensions.Logging;
using System.Text;
using Autofac.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Hosting;
using Admin.Core.IService.ISys;
using Admin.Core.Tasks;
using Microsoft.AspNetCore.Builder;
using Google.Protobuf.WellKnownTypes;
namespace Admin.Core.Wpf
{
///
/// Interaction logic for App.xaml
///
public partial class App : Application
{
public static IServiceProvider ServiceProvider;
protected override async void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
var host = CreateHostBuilder(e.Args).Build();//生成宿主。
ServiceProvider = host.Services;
host.Services.GetRequiredService()?.Show();
await host.StartAsync();
}
///
/// CreateHostBuilder
///
///
///
public static IHostBuilder CreateHostBuilder(string[] args)
{
//初始化默认主机Builder
var hostBuilder = Host.CreateDefaultBuilder(args)
//Autofac服务工厂
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup();
})
.ConfigureLogging((hostingContext, builder) =>
{
//清楚控制台log日志
builder.ClearProviders();
// 1.过滤掉系统默认的一些日志
builder.AddFilter("System", LogLevel.Error);
builder.AddFilter("Microsoft", LogLevel.Error);
// 默认log4net.confg
builder.AddLog4Net(Path.Combine(Directory.GetCurrentDirectory(), "Log4net.config"));
});
return hostBuilder;
}
}
}