-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring: UI TopLevel services and MainWindowViewModel injection (#…
…744) * fix: Don't trigger memory read breakpoints (disasm) ... and don't support writes, as it is unused. Signed-off-by: Maximilien Noal <[email protected]> * removed unused using Signed-off-by: Maximilien Noal <[email protected]> * refactor: UI uses DI for most services Signed-off-by: Maximilien Noal <[email protected]> * fix: Double validation errors (AvaloniaUI + CI) Signed-off-by: Maximilien Noal <[email protected]> * refactor: MainWindowViewModel is an injected service now Signed-off-by: Maximilien Noal <[email protected]> * refactor: removed commands about starting a new program Signed-off-by: Maximilien Noal <[email protected]> * refactor: CommandLineParser is an injected service Signed-off-by: Maximilien Noal <[email protected]> --------- Signed-off-by: Maximilien Noal <[email protected]>
- Loading branch information
1 parent
9d01f58
commit 64a7a7f
Showing
14 changed files
with
153 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace Spice86.Core.CLI; | ||
|
||
using System.Diagnostics; | ||
|
||
/// <summary> | ||
/// Parses the command line options to create a <see cref="Configuration"/>. | ||
/// </summary> | ||
public interface ICommandLineParser { | ||
/// <summary> | ||
/// Parses the command line into a <see cref="Configuration"/> object. | ||
/// </summary> | ||
/// <param name="args">The application command line arguments</param> | ||
/// <returns>A <see cref="Configuration"/> object representing the command line arguments</returns> | ||
/// <exception cref="UnreachableException">When the command line arguments are unrecognized.</exception> | ||
public Configuration ParseCommandLine(string[] args); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/Spice86/DependencyInjection/ServiceCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
namespace Spice86.DependencyInjection; | ||
|
||
using Avalonia.Controls; | ||
using Avalonia.Platform.Storage; | ||
using Avalonia.Threading; | ||
|
||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
using Spice86.Core.CLI; | ||
using Spice86.Infrastructure; | ||
using Spice86.Logging; | ||
using Spice86.Shared.Interfaces; | ||
|
||
public static class ServiceCollectionExtensions { | ||
public static void AddConfiguration(this IServiceCollection serviceCollection, string[] args) { | ||
serviceCollection.AddSingleton<ICommandLineParser, CommandLineParser>(); | ||
serviceCollection.AddSingleton<Configuration>(serviceProvider => { | ||
ICommandLineParser commandLineParser = serviceProvider.GetRequiredService<ICommandLineParser>(); | ||
return commandLineParser.ParseCommandLine(args); | ||
}); | ||
} | ||
|
||
public static void AddLogging(this IServiceCollection serviceCollection) { | ||
serviceCollection.AddSingleton<ILoggerPropertyBag, LoggerPropertyBag>(); | ||
serviceCollection.AddSingleton<ILoggerService, LoggerService>((serviceProvider) => { | ||
Configuration configuration = serviceProvider.GetRequiredService<Configuration>(); | ||
LoggerService loggerService = new LoggerService(serviceProvider.GetRequiredService<ILoggerPropertyBag>()); | ||
Startup.SetLoggingLevel(loggerService, configuration); | ||
return loggerService; | ||
}); | ||
} | ||
|
||
public static void AddGuiInfrastructure(this IServiceCollection serviceCollection, TopLevel mainWindow) { | ||
serviceCollection.AddSingleton<IAvaloniaKeyScanCodeConverter, AvaloniaKeyScanCodeConverter>(); | ||
serviceCollection.AddSingleton<IWindowService, WindowService>(); | ||
serviceCollection.AddSingleton<IUIDispatcher, UIDispatcher>((_) => new UIDispatcher(Dispatcher.UIThread)); | ||
serviceCollection.AddSingleton<IUIDispatcherTimerFactory, UIDispatcherTimerFactory>(); | ||
serviceCollection.AddSingleton<IStorageProvider>((_) => mainWindow.StorageProvider); | ||
serviceCollection.AddSingleton<IHostStorageProvider, HostStorageProvider>(); | ||
serviceCollection.AddSingleton<ITextClipboard>((_) => new TextClipboard(mainWindow.Clipboard)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.