initial commit
This commit is contained in:
78
BlueMine/App.xaml.cs
Normal file
78
BlueMine/App.xaml.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
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<SettingsManager>();
|
||||
|
||||
services.AddSingleton(sp =>
|
||||
{
|
||||
var manager = sp.GetRequiredService<SettingsManager>();
|
||||
return manager.Load();
|
||||
});
|
||||
|
||||
//services.AddTransient<RedmineAuthHandler>();
|
||||
services.AddHttpClient<RedmineManager>(client => client.BaseAddress = new Uri("http://localhost/"));
|
||||
// .AddHttpMessageHandler<RedmineAuthHandler>();
|
||||
|
||||
services.AddSingleton<RedmineManager>();
|
||||
services.AddSingleton<MainWindow>();
|
||||
}).Build();
|
||||
|
||||
/// <summary>
|
||||
/// Gets services.
|
||||
/// </summary>
|
||||
public static IServiceProvider Services
|
||||
{
|
||||
get { return _host.Services; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the application is loading.
|
||||
/// </summary>
|
||||
private async void OnStartup(object sender, StartupEventArgs e)
|
||||
{
|
||||
await _host.StartAsync();
|
||||
var mainWindow = _host.Services.GetRequiredService<MainWindow>();
|
||||
mainWindow.Show();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the application is closing.
|
||||
/// </summary>
|
||||
private async void OnExit(object sender, ExitEventArgs e)
|
||||
{
|
||||
await _host.StopAsync();
|
||||
|
||||
_host.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when an exception is thrown by an application but not handled.
|
||||
/// </summary>
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user