File scoped namespace
This commit is contained in:
@@ -7,40 +7,39 @@ using FileTime.GuiApp.Views;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FileTime.GuiApp
|
||||
namespace FileTime.GuiApp;
|
||||
|
||||
public partial class App : Application
|
||||
{
|
||||
public partial class App : Application
|
||||
static App()
|
||||
{
|
||||
static App()
|
||||
{
|
||||
DI.ServiceProvider ??= DependencyInjection
|
||||
.RegisterDefaultServices()
|
||||
.AddConfiguration()
|
||||
.RegisterLogging()
|
||||
.RegisterServices()
|
||||
.AddViewModels()
|
||||
.BuildServiceProvider()
|
||||
.InitSerilog();
|
||||
DI.ServiceProvider ??= DependencyInjection
|
||||
.RegisterDefaultServices()
|
||||
.AddConfiguration()
|
||||
.RegisterLogging()
|
||||
.RegisterServices()
|
||||
.AddViewModels()
|
||||
.BuildServiceProvider()
|
||||
.InitSerilog();
|
||||
|
||||
var logger = DI.ServiceProvider.GetRequiredService<ILogger<App>>();
|
||||
logger.LogInformation("App initialization completed");
|
||||
}
|
||||
public override void Initialize()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
var logger = DI.ServiceProvider.GetRequiredService<ILogger<App>>();
|
||||
logger.LogInformation("App initialization completed");
|
||||
}
|
||||
public override void Initialize()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
|
||||
public override void OnFrameworkInitializationCompleted()
|
||||
public override void OnFrameworkInitializationCompleted()
|
||||
{
|
||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
desktop.MainWindow = new MainWindow
|
||||
{
|
||||
desktop.MainWindow = new MainWindow
|
||||
{
|
||||
DataContext = new MainWindowLoadingViewModel(),
|
||||
};
|
||||
}
|
||||
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
DataContext = new MainWindowLoadingViewModel(),
|
||||
};
|
||||
}
|
||||
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,11 @@
|
||||
<ApplicationIcon>filetime.ico</ApplicationIcon>
|
||||
<Version>0.0.1</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="filetime.ico" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -3,19 +3,19 @@ using System.IO;
|
||||
using Avalonia;
|
||||
using Avalonia.ReactiveUI;
|
||||
|
||||
namespace FileTime.GuiApp
|
||||
namespace FileTime.GuiApp;
|
||||
|
||||
public static class Program
|
||||
{
|
||||
public static class Program
|
||||
public static string AppDataRoot { get; }
|
||||
public static string EnvironmentName { get; }
|
||||
|
||||
static Program()
|
||||
{
|
||||
public static string AppDataRoot { get; }
|
||||
public static string EnvironmentName { get; }
|
||||
|
||||
static Program()
|
||||
{
|
||||
#if DEBUG
|
||||
EnvironmentName = "Development";
|
||||
EnvironmentName = "Development";
|
||||
|
||||
AppDataRoot = Path.Combine(Environment.CurrentDirectory, "appdata");
|
||||
AppDataRoot = Path.Combine(Environment.CurrentDirectory, "appdata");
|
||||
#else
|
||||
EnvironmentName = "Release";
|
||||
|
||||
@@ -43,20 +43,19 @@ namespace FileTime.GuiApp
|
||||
if (appDataRoot == null) throw new UnauthorizedAccessException();
|
||||
AppDataRoot = appDataRoot;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Initialization code. Don't use any Avalonia, third-party APIs or any
|
||||
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
|
||||
// yet and stuff might break.
|
||||
[STAThread]
|
||||
public static void Main(string[] args) => BuildAvaloniaApp()
|
||||
.StartWithClassicDesktopLifetime(args);
|
||||
|
||||
// Avalonia configuration, don't remove; also used by visual designer.
|
||||
public static AppBuilder BuildAvaloniaApp()
|
||||
=> AppBuilder.Configure<App>()
|
||||
.UsePlatformDetect()
|
||||
.UseReactiveUI()
|
||||
.LogToTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// Initialization code. Don't use any Avalonia, third-party APIs or any
|
||||
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
|
||||
// yet and stuff might break.
|
||||
[STAThread]
|
||||
public static void Main(string[] args) => BuildAvaloniaApp()
|
||||
.StartWithClassicDesktopLifetime(args);
|
||||
|
||||
// Avalonia configuration, don't remove; also used by visual designer.
|
||||
public static AppBuilder BuildAvaloniaApp()
|
||||
=> AppBuilder.Configure<App>()
|
||||
.UsePlatformDetect()
|
||||
.UseReactiveUI()
|
||||
.LogToTrace();
|
||||
}
|
||||
@@ -11,70 +11,69 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Serilog;
|
||||
using Serilog.Configuration;
|
||||
|
||||
namespace FileTime.GuiApp
|
||||
namespace FileTime.GuiApp;
|
||||
|
||||
public static class Startup
|
||||
{
|
||||
public static class Startup
|
||||
internal static IServiceCollection AddViewModels(this IServiceCollection serviceCollection)
|
||||
{
|
||||
internal static IServiceCollection AddViewModels(this IServiceCollection serviceCollection)
|
||||
{
|
||||
return serviceCollection
|
||||
.AddSingleton<MainWindowViewModel>()
|
||||
.AddSingleton<GuiAppState>()
|
||||
.AddSingleton<IAppState, GuiAppState>(s => s.GetRequiredService<GuiAppState>())
|
||||
.AddSingleton<IGuiAppState, GuiAppState>(s => s.GetRequiredService<GuiAppState>());
|
||||
}
|
||||
internal static IServiceCollection RegisterServices(this IServiceCollection serviceCollection)
|
||||
{
|
||||
return serviceCollection
|
||||
.AddSingleton<IRxSchedulerService, AvaloniaRxSchedulerService>()
|
||||
.AddSingleton<IKeyInputHandlerService, KeyInputHandlerService>()
|
||||
.AddSingleton<IDefaultModeKeyInputHandler, DefaultModeKeyInputHandler>()
|
||||
.AddSingleton<IKeyboardConfigurationService, KeyboardConfigurationService>()
|
||||
.AddSingleton<IRapidTravelModeKeyInputHandler, RapidTravelModeKeyInputHandler>();
|
||||
}
|
||||
return serviceCollection
|
||||
.AddSingleton<MainWindowViewModel>()
|
||||
.AddSingleton<GuiAppState>()
|
||||
.AddSingleton<IAppState, GuiAppState>(s => s.GetRequiredService<GuiAppState>())
|
||||
.AddSingleton<IGuiAppState, GuiAppState>(s => s.GetRequiredService<GuiAppState>());
|
||||
}
|
||||
internal static IServiceCollection RegisterServices(this IServiceCollection serviceCollection)
|
||||
{
|
||||
return serviceCollection
|
||||
.AddSingleton<IRxSchedulerService, AvaloniaRxSchedulerService>()
|
||||
.AddSingleton<IKeyInputHandlerService, KeyInputHandlerService>()
|
||||
.AddSingleton<IDefaultModeKeyInputHandler, DefaultModeKeyInputHandler>()
|
||||
.AddSingleton<IKeyboardConfigurationService, KeyboardConfigurationService>()
|
||||
.AddSingleton<IRapidTravelModeKeyInputHandler, RapidTravelModeKeyInputHandler>();
|
||||
}
|
||||
|
||||
internal static IServiceCollection RegisterLogging(this IServiceCollection serviceCollection)
|
||||
{
|
||||
return serviceCollection.AddLogging(loggingBuilder =>
|
||||
loggingBuilder.AddSerilog(dispose: true)
|
||||
);
|
||||
}
|
||||
internal static IServiceCollection RegisterLogging(this IServiceCollection serviceCollection)
|
||||
{
|
||||
return serviceCollection.AddLogging(loggingBuilder =>
|
||||
loggingBuilder.AddSerilog(dispose: true)
|
||||
);
|
||||
}
|
||||
|
||||
internal static IServiceCollection AddConfiguration(this IServiceCollection serviceCollection)
|
||||
{
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.AddInMemoryCollection(MainConfiguration.Configuration)
|
||||
.AddJsonFile("appsettings.json", optional: true)
|
||||
.AddJsonFile($"appsettings.{Program.EnvironmentName}.json", true)
|
||||
.Build();
|
||||
internal static IServiceCollection AddConfiguration(this IServiceCollection serviceCollection)
|
||||
{
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.AddInMemoryCollection(MainConfiguration.Configuration)
|
||||
.AddJsonFile("appsettings.json", optional: true)
|
||||
.AddJsonFile($"appsettings.{Program.EnvironmentName}.json", true)
|
||||
.Build();
|
||||
|
||||
return serviceCollection
|
||||
.Configure<ProgramsConfiguration>(configuration.GetSection(SectionNames.ProgramsSectionName))
|
||||
.Configure<KeyBindingConfiguration>(configuration.GetSection(SectionNames.KeybindingSectionName))
|
||||
.AddSingleton<IConfiguration>(configuration);
|
||||
}
|
||||
return serviceCollection
|
||||
.Configure<ProgramsConfiguration>(configuration.GetSection(SectionNames.ProgramsSectionName))
|
||||
.Configure<KeyBindingConfiguration>(configuration.GetSection(SectionNames.KeybindingSectionName))
|
||||
.AddSingleton<IConfiguration>(configuration);
|
||||
}
|
||||
|
||||
internal static IServiceProvider InitSerilog(this IServiceProvider serviceProvider)
|
||||
{
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.ReadFrom.Configuration(serviceProvider.GetService<IConfiguration>())
|
||||
.Enrich.FromLogContext()
|
||||
.WriteTo.File(
|
||||
Path.Combine(Program.AppDataRoot, "logs", "appLog.log"),
|
||||
fileSizeLimitBytes: 10 * 1024 * 1024,
|
||||
rollOnFileSizeLimit: true,
|
||||
rollingInterval: RollingInterval.Day)
|
||||
.WriteTo.MessageBoxSink(serviceProvider)
|
||||
.CreateLogger();
|
||||
internal static IServiceProvider InitSerilog(this IServiceProvider serviceProvider)
|
||||
{
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.ReadFrom.Configuration(serviceProvider.GetService<IConfiguration>())
|
||||
.Enrich.FromLogContext()
|
||||
.WriteTo.File(
|
||||
Path.Combine(Program.AppDataRoot, "logs", "appLog.log"),
|
||||
fileSizeLimitBytes: 10 * 1024 * 1024,
|
||||
rollOnFileSizeLimit: true,
|
||||
rollingInterval: RollingInterval.Day)
|
||||
.WriteTo.MessageBoxSink(serviceProvider)
|
||||
.CreateLogger();
|
||||
|
||||
return serviceProvider;
|
||||
}
|
||||
return serviceProvider;
|
||||
}
|
||||
|
||||
internal static LoggerConfiguration MessageBoxSink(
|
||||
this LoggerSinkConfiguration loggerConfiguration,
|
||||
IServiceProvider serviceProvider)
|
||||
{
|
||||
return loggerConfiguration.Sink(serviceProvider.GetService<ToastMessageSink>());
|
||||
}
|
||||
internal static LoggerConfiguration MessageBoxSink(
|
||||
this LoggerSinkConfiguration loggerConfiguration,
|
||||
IServiceProvider serviceProvider)
|
||||
{
|
||||
return loggerConfiguration.Sink(serviceProvider.GetService<ToastMessageSink>());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user