using BlueMine.Redmine;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System.IO;
using System.Windows;
using System.Windows.Threading;
namespace BlueMine
{
///
/// Interaction logic for App.xaml
///
public partial class App : Application
{
private static readonly IHost _host = Host
.CreateDefaultBuilder()
.ConfigureLogging(builder => {
builder.AddConsole();
builder.SetMinimumLevel(LogLevel.Debug);
})
.ConfigureAppConfiguration(c => { c.SetBasePath(Path.GetDirectoryName(AppContext.BaseDirectory) ?? throw new NullReferenceException()); })
.ConfigureServices((context, services) =>
{
services.AddSingleton();
services.AddSingleton(sp =>
{
var manager = sp.GetRequiredService();
return manager.Load();
});
//services.AddTransient();
services.AddHttpClient(client => client.BaseAddress = new Uri("http://localhost/"));
// .AddHttpMessageHandler();
services.AddSingleton();
services.AddSingleton();
}).Build();
///
/// Gets services.
///
public static IServiceProvider Services
{
get { return _host.Services; }
}
///
/// Occurs when the application is loading.
///
private async void OnStartup(object sender, StartupEventArgs e)
{
await _host.StartAsync();
var mainWindow = _host.Services.GetRequiredService();
mainWindow.Show();
}
///
/// Occurs when the application is closing.
///
private async void OnExit(object sender, ExitEventArgs e)
{
await _host.StopAsync();
_host.Dispose();
}
///
/// Occurs when an exception is thrown by an application but not handled.
///
private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
// For more info see https://docs.microsoft.com/en-us/dotnet/api/system.windows.application.dispatcherunhandledexception?view=windowsdesktop-6.0
}
}
}