You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.9 KiB
72 lines
2.9 KiB
using BBWY.Client.Models;
|
|
using BBWY.Common.Extensions;
|
|
using BBWY.Common.Http;
|
|
using BBWY.Common.Models;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using System;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
|
|
namespace BBWY.Client
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for App.xaml
|
|
/// </summary>
|
|
public partial class App : Application
|
|
{
|
|
public IServiceProvider ServiceProvider { get; private set; }
|
|
public IConfiguration Configuration { get; private set; }
|
|
|
|
protected override void OnStartup(StartupEventArgs e)
|
|
{
|
|
var gl = new GlobalContext();
|
|
|
|
#region 注册全局异常
|
|
this.DispatcherUnhandledException += App_DispatcherUnhandledException; ;
|
|
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; ;
|
|
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException; ;
|
|
#endregion
|
|
|
|
var applicationPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
|
var builder = new ConfigurationBuilder().SetBasePath(applicationPath).AddJsonFile("BBWYAppSettings.json", false, true);
|
|
Configuration = builder.Build();
|
|
gl.BBYWApiHost = Configuration.GetSection("BBWYApiHost").Value;
|
|
gl.MDSApiHost = Configuration.GetSection("MDSApiHost").Value;
|
|
gl.JOSApiHost = Configuration.GetSection("JOSApiHost").Value;
|
|
gl._1688ApiHost = Configuration.GetSection("1688ApiHost").Value;
|
|
|
|
IServiceCollection serviceCollection = new ServiceCollection();
|
|
serviceCollection.AddHttpClient();
|
|
serviceCollection.AddSingleton<RestApiService>();
|
|
serviceCollection.AddSingleton(gl);
|
|
//serviceCollection.AddSingleton<MainViewModel>();
|
|
//serviceCollection.AddSingleton<WareManagerViewModel>();
|
|
//serviceCollection.AddSingleton<WareStockViewModel>();
|
|
serviceCollection.BatchRegisterServices(new Assembly[] { Assembly.Load("BBWY.Client") }, typeof(IDenpendency));
|
|
|
|
serviceCollection.AddMapper(new MappingProfile());
|
|
|
|
ServiceProvider = serviceCollection.BuildServiceProvider();
|
|
base.OnStartup(e);
|
|
}
|
|
|
|
private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
|
|
{
|
|
Console.WriteLine(e.Exception);
|
|
e.SetObserved();
|
|
}
|
|
|
|
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
|
|
{
|
|
Console.WriteLine(e.Exception);
|
|
}
|
|
}
|
|
}
|
|
|