From f2ef657d002f2d77b6a8757d7f2225edcf949aa9 Mon Sep 17 00:00:00 2001 From: Robert Date: Sat, 4 Feb 2023 23:25:48 +0100 Subject: [PATCH 1/6] Core - Refactor service registration --- .../DryIoc/ContainerExtensions.cs | 66 +++++++++++++++++++ src/Artemis.Core/DryIoc/CoreModule.cs | 48 -------------- src/Artemis.Core/DryIoc/IModule.cs | 15 ----- src/Artemis.Core/DryIoc/PluginModule.cs | 26 -------- .../Services/PluginManagementService.cs | 2 +- src/Artemis.UI.Linux/App.axaml.cs | 3 +- .../DryIoc/ContainerExtensions.cs | 20 ++++++ src/Artemis.UI.Linux/DryIoc/LinuxModule.cs | 17 ----- .../DryIoc/ContainerExtensions.cs | 21 ++++++ .../DryIoc/SharedUIModule.cs | 19 ------ src/Artemis.UI.Windows/App.axaml.cs | 2 +- .../DryIoc/ContainerExtensions.cs | 27 ++++++++ .../DryIoc/WindowsModule.cs | 22 ------- src/Artemis.UI/ArtemisBootstrapper.cs | 24 ++++--- src/Artemis.UI/DryIoc/ContainerExtensions.cs | 42 ++++++++++++ src/Artemis.UI/DryIoc/UiModule.cs | 36 ---------- .../DryIoc/ContainerExtensions.cs | 40 +++++++++++ .../DryIoc/NoStringNinjectModule.cs | 35 ---------- 18 files changed, 234 insertions(+), 231 deletions(-) create mode 100644 src/Artemis.Core/DryIoc/ContainerExtensions.cs delete mode 100644 src/Artemis.Core/DryIoc/CoreModule.cs delete mode 100644 src/Artemis.Core/DryIoc/IModule.cs delete mode 100644 src/Artemis.Core/DryIoc/PluginModule.cs create mode 100644 src/Artemis.UI.Linux/DryIoc/ContainerExtensions.cs delete mode 100644 src/Artemis.UI.Linux/DryIoc/LinuxModule.cs create mode 100644 src/Artemis.UI.Shared/DryIoc/ContainerExtensions.cs delete mode 100644 src/Artemis.UI.Shared/DryIoc/SharedUIModule.cs create mode 100644 src/Artemis.UI.Windows/DryIoc/ContainerExtensions.cs delete mode 100644 src/Artemis.UI.Windows/DryIoc/WindowsModule.cs create mode 100644 src/Artemis.UI/DryIoc/ContainerExtensions.cs delete mode 100644 src/Artemis.UI/DryIoc/UiModule.cs create mode 100644 src/Artemis.VisualScripting/DryIoc/ContainerExtensions.cs delete mode 100644 src/Artemis.VisualScripting/DryIoc/NoStringNinjectModule.cs diff --git a/src/Artemis.Core/DryIoc/ContainerExtensions.cs b/src/Artemis.Core/DryIoc/ContainerExtensions.cs new file mode 100644 index 000000000..4f418d453 --- /dev/null +++ b/src/Artemis.Core/DryIoc/ContainerExtensions.cs @@ -0,0 +1,66 @@ +using System; +using System.Linq; +using System.Reflection; +using Artemis.Core.DryIoc.Factories; +using Artemis.Core.Services; +using Artemis.Storage; +using Artemis.Storage.Migrations.Interfaces; +using Artemis.Storage.Repositories.Interfaces; +using DryIoc; + +namespace Artemis.Core.DryIoc; + +/// +/// Provides an extension method to register services onto a DryIoc . +/// +public static class CoreContainerExtensions +{ + /// + /// Registers core services into the container. + /// + /// The builder building the current container + public static void RegisterCore(this IContainer container) + { + Assembly[] coreAssembly = {typeof(IArtemisService).Assembly}; + Assembly[] storageAssembly = {typeof(IRepository).Assembly}; + + // Bind all services as singletons + container.RegisterMany(coreAssembly, type => type.IsAssignableTo(), Reuse.Singleton); + container.RegisterMany(coreAssembly, type => type.IsAssignableTo(), Reuse.Singleton, setup: Setup.With(condition: HasAccessToProtectedService)); + + // Bind storage + container.RegisterDelegate(() => StorageManager.CreateRepository(Constants.DataFolder), Reuse.Singleton); + container.Register(Reuse.Singleton); + container.RegisterMany(storageAssembly, type => type.IsAssignableTo(), Reuse.Singleton); + + // Bind migrations + container.RegisterMany(storageAssembly, type => type.IsAssignableTo(), Reuse.Singleton, nonPublicServiceTypes: true); + + container.Register(Reuse.Singleton); + container.Register(made: Made.Of(_ => ServiceInfo.Of(), f => f.CreatePluginSettings(Arg.Index(0)), r => r.Parent.ImplementationType)); + container.Register(Reuse.Singleton); + container.Register(made: Made.Of(_ => ServiceInfo.Of(), f => f.CreateLogger(Arg.Index(0)), r => r.Parent.ImplementationType)); + } + + /// + /// Registers plugin services into the container, this is typically a child container. + /// + /// The builder building the current container + /// The plugin to register + public static void RegisterPlugin(this IContainer container, Plugin plugin) + { + container.RegisterInstance(plugin, setup: Setup.With(preventDisposal: true)); + + // Bind plugin service interfaces, DryIoc expects at least one match when calling RegisterMany so ensure there is something to register first + if (plugin.Assembly != null && plugin.Assembly.GetTypes().Any(t => t.IsAssignableTo())) + container.RegisterMany(new[] {plugin.Assembly}, type => type.IsAssignableTo(), Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep); + } + + private static bool HasAccessToProtectedService(Request request) + { + // Plugin assembly locations may not be set for some reason, that case it's also not allowed >:( + return request.Parent.ImplementationType != null && + !string.IsNullOrWhiteSpace(request.Parent.ImplementationType.Assembly.Location) && + !request.Parent.ImplementationType.Assembly.Location.StartsWith(Constants.PluginsFolder); + } +} \ No newline at end of file diff --git a/src/Artemis.Core/DryIoc/CoreModule.cs b/src/Artemis.Core/DryIoc/CoreModule.cs deleted file mode 100644 index 0c41cb524..000000000 --- a/src/Artemis.Core/DryIoc/CoreModule.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using System.Reflection; -using Artemis.Core.DryIoc.Factories; -using Artemis.Core.Services; -using Artemis.Storage; -using Artemis.Storage.Migrations.Interfaces; -using Artemis.Storage.Repositories.Interfaces; -using DryIoc; - -namespace Artemis.Core.DryIoc; - -/// -/// The main of the Artemis Core that binds all services -/// -public class CoreModule : IModule -{ - /// - public void Load(IRegistrator builder) - { - Assembly coreAssembly = typeof(IArtemisService).Assembly; - Assembly storageAssembly = typeof(IRepository).Assembly; - - // Bind all services as singletons - builder.RegisterMany(new[] {coreAssembly}, type => type.IsAssignableTo(), Reuse.Singleton); - builder.RegisterMany(new[] {coreAssembly}, type => type.IsAssignableTo(), Reuse.Singleton, setup: Setup.With(condition: HasAccessToProtectedService)); - - // Bind storage - builder.RegisterDelegate(() => StorageManager.CreateRepository(Constants.DataFolder), Reuse.Singleton); - builder.Register(Reuse.Singleton); - builder.RegisterMany(new[] {storageAssembly}, type => type.IsAssignableTo(), Reuse.Singleton); - - // Bind migrations - builder.RegisterMany(new[] { storageAssembly }, type => type.IsAssignableTo(), Reuse.Singleton, nonPublicServiceTypes: true); - - builder.Register(Reuse.Singleton); - builder.Register(made: Made.Of(_ => ServiceInfo.Of(), factory => factory.CreatePluginSettings(Arg.Index(0)), r => r.Parent.ImplementationType)); - builder.Register(Reuse.Singleton); - builder.Register(made: Made.Of(_ => ServiceInfo.Of(), f => f.CreateLogger(Arg.Index(0)), r => r.Parent.ImplementationType)); - } - - private bool HasAccessToProtectedService(Request request) - { - // Plugin assembly locations may not be set for some reason, that case it's also not allowed >:( - return request.Parent.ImplementationType != null && - !string.IsNullOrWhiteSpace(request.Parent.ImplementationType.Assembly.Location) && - !request.Parent.ImplementationType.Assembly.Location.StartsWith(Constants.PluginsFolder); - } -} \ No newline at end of file diff --git a/src/Artemis.Core/DryIoc/IModule.cs b/src/Artemis.Core/DryIoc/IModule.cs deleted file mode 100644 index 08b3247a9..000000000 --- a/src/Artemis.Core/DryIoc/IModule.cs +++ /dev/null @@ -1,15 +0,0 @@ -using DryIoc; - -namespace Artemis.Core.DryIoc; - -/** - * Represents a service module. - */ -public interface IModule -{ - /// - /// Registers the services provided by the module. - /// - /// The builder to register the services with. - void Load(IRegistrator builder); -} \ No newline at end of file diff --git a/src/Artemis.Core/DryIoc/PluginModule.cs b/src/Artemis.Core/DryIoc/PluginModule.cs deleted file mode 100644 index d6ae8dd07..000000000 --- a/src/Artemis.Core/DryIoc/PluginModule.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Linq; -using Artemis.Core.Services; -using DryIoc; - -namespace Artemis.Core.DryIoc; - -internal class PluginModule : IModule -{ - public PluginModule(Plugin plugin) - { - Plugin = plugin ?? throw new ArgumentNullException(nameof(plugin)); - } - - public Plugin Plugin { get; } - - /// - public void Load(IRegistrator builder) - { - builder.RegisterInstance(Plugin, setup: Setup.With(preventDisposal: true)); - - // Bind plugin service interfaces, DryIoc expects at least one match when calling RegisterMany so ensure there is something to register first - if (Plugin.Assembly != null && Plugin.Assembly.GetTypes().Any(t => t.IsAssignableTo())) - builder.RegisterMany(new[] {Plugin.Assembly}, type => type.IsAssignableTo(), Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep); - } -} \ No newline at end of file diff --git a/src/Artemis.Core/Services/PluginManagementService.cs b/src/Artemis.Core/Services/PluginManagementService.cs index 9565f6320..6de473234 100644 --- a/src/Artemis.Core/Services/PluginManagementService.cs +++ b/src/Artemis.Core/Services/PluginManagementService.cs @@ -435,7 +435,7 @@ internal class PluginManagementService : IPluginManagementService plugin.Container = _container.CreateChild(newRules: _container.Rules.WithConcreteTypeDynamicRegistrations()); try { - new PluginModule(plugin).Load(plugin.Container); + plugin.Container.RegisterPlugin(plugin); } catch (Exception e) { diff --git a/src/Artemis.UI.Linux/App.axaml.cs b/src/Artemis.UI.Linux/App.axaml.cs index f3fdb04cf..7040f8183 100644 --- a/src/Artemis.UI.Linux/App.axaml.cs +++ b/src/Artemis.UI.Linux/App.axaml.cs @@ -1,4 +1,5 @@ using Artemis.Core.Services; +using Artemis.UI.Linux.DryIoc; using Artemis.UI.Linux.Providers.Input; using Avalonia; using Avalonia.Controls; @@ -17,7 +18,7 @@ public class App : Application public override void Initialize() { - _container = ArtemisBootstrapper.Bootstrap(this); + _container = ArtemisBootstrapper.Bootstrap(this, c => c.RegisterProviders()); Program.CreateLogger(_container); RxApp.MainThreadScheduler = AvaloniaScheduler.Instance; AvaloniaXamlLoader.Load(this); diff --git a/src/Artemis.UI.Linux/DryIoc/ContainerExtensions.cs b/src/Artemis.UI.Linux/DryIoc/ContainerExtensions.cs new file mode 100644 index 000000000..8647beea5 --- /dev/null +++ b/src/Artemis.UI.Linux/DryIoc/ContainerExtensions.cs @@ -0,0 +1,20 @@ +using Artemis.Core.Services; +using Artemis.UI.Linux.Providers.Input; +using DryIoc; + +namespace Artemis.UI.Linux.DryIoc; + +/// +/// Provides an extension method to register services onto a DryIoc . +/// +public static class UIContainerExtensions +{ + /// + /// Registers providers into the container. + /// + /// The builder building the current container + public static void RegisterProviders(this IContainer container) + { + container.Register(serviceKey: LinuxInputProvider.Id); + } +} \ No newline at end of file diff --git a/src/Artemis.UI.Linux/DryIoc/LinuxModule.cs b/src/Artemis.UI.Linux/DryIoc/LinuxModule.cs deleted file mode 100644 index 142e8b667..000000000 --- a/src/Artemis.UI.Linux/DryIoc/LinuxModule.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Artemis.Core.DryIoc; -using Artemis.Core.Services; -using Artemis.UI.Linux.Providers.Input; -using DryIoc; - -namespace Artemis.UI.Linux.DryIoc; - -public class LinuxModule : IModule -{ - - /// - public void Load(IRegistrator builder) - { - builder.Register(serviceKey: LinuxInputProvider.Id); - } - -} \ No newline at end of file diff --git a/src/Artemis.UI.Shared/DryIoc/ContainerExtensions.cs b/src/Artemis.UI.Shared/DryIoc/ContainerExtensions.cs new file mode 100644 index 000000000..cb7baef36 --- /dev/null +++ b/src/Artemis.UI.Shared/DryIoc/ContainerExtensions.cs @@ -0,0 +1,21 @@ +using System.Reflection; +using Artemis.UI.Shared.Services; +using DryIoc; + +namespace Artemis.UI.Shared.DryIoc; + +/// +/// Provides an extension method to register services onto a DryIoc . +/// +public static class UIContainerExtensions +{ + /// + /// Registers shared UI services into the container. + /// + /// The builder building the current container + public static void RegisterSharedUI(this IContainer container) + { + Assembly artemisShared = typeof(IArtemisSharedUIService).GetAssembly(); + container.RegisterMany(new[] { artemisShared }, type => type.IsAssignableTo(), Reuse.Singleton); + } +} \ No newline at end of file diff --git a/src/Artemis.UI.Shared/DryIoc/SharedUIModule.cs b/src/Artemis.UI.Shared/DryIoc/SharedUIModule.cs deleted file mode 100644 index be6fcced3..000000000 --- a/src/Artemis.UI.Shared/DryIoc/SharedUIModule.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Reflection; -using Artemis.Core.DryIoc; -using Artemis.UI.Shared.Services; -using DryIoc; - -namespace Artemis.UI.Shared.DryIoc; - -/// -/// The main of the Artemis Shared UI toolkit that binds all services -/// -public class SharedUIModule : IModule -{ - /// - public void Load(IRegistrator builder) - { - Assembly artemisShared = typeof(IArtemisSharedUIService).GetAssembly(); - builder.RegisterMany(new[] { artemisShared }, type => type.IsAssignableTo(), Reuse.Singleton); - } -} \ No newline at end of file diff --git a/src/Artemis.UI.Windows/App.axaml.cs b/src/Artemis.UI.Windows/App.axaml.cs index 38f0389a7..b2a8db3df 100644 --- a/src/Artemis.UI.Windows/App.axaml.cs +++ b/src/Artemis.UI.Windows/App.axaml.cs @@ -33,7 +33,7 @@ public class App : Application Environment.Exit(1); } - _container = ArtemisBootstrapper.Bootstrap(this, new WindowsModule()); + _container = ArtemisBootstrapper.Bootstrap(this, c => c.RegisterProviders()); Program.CreateLogger(_container); RxApp.MainThreadScheduler = AvaloniaScheduler.Instance; AvaloniaXamlLoader.Load(this); diff --git a/src/Artemis.UI.Windows/DryIoc/ContainerExtensions.cs b/src/Artemis.UI.Windows/DryIoc/ContainerExtensions.cs new file mode 100644 index 000000000..000931d92 --- /dev/null +++ b/src/Artemis.UI.Windows/DryIoc/ContainerExtensions.cs @@ -0,0 +1,27 @@ +using Artemis.Core.Providers; +using Artemis.Core.Services; +using Artemis.UI.Shared.Providers; +using Artemis.UI.Windows.Providers; +using Artemis.UI.Windows.Providers.Input; +using DryIoc; + +namespace Artemis.UI.Windows.DryIoc; + +/// +/// Provides an extension method to register services onto a DryIoc . +/// +public static class UIContainerExtensions +{ + /// + /// Registers providers into the container. + /// + /// The builder building the current container + public static void RegisterProviders(this IContainer container) + { + container.Register(Reuse.Singleton); + container.Register(Reuse.Singleton); + container.Register(Reuse.Singleton); + container.Register(); + container.Register(serviceKey: WindowsInputProvider.Id); + } +} \ No newline at end of file diff --git a/src/Artemis.UI.Windows/DryIoc/WindowsModule.cs b/src/Artemis.UI.Windows/DryIoc/WindowsModule.cs deleted file mode 100644 index 96b8b7ec7..000000000 --- a/src/Artemis.UI.Windows/DryIoc/WindowsModule.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Artemis.Core.DryIoc; -using Artemis.Core.Providers; -using Artemis.Core.Services; -using Artemis.UI.Shared.Providers; -using Artemis.UI.Windows.Providers; -using Artemis.UI.Windows.Providers.Input; -using DryIoc; - -namespace Artemis.UI.Windows.DryIoc; - -public class WindowsModule : IModule -{ - /// - public void Load(IRegistrator builder) - { - builder.Register(Reuse.Singleton); - builder.Register(Reuse.Singleton); - builder.Register(Reuse.Singleton); - builder.Register(); - builder.Register(serviceKey: WindowsInputProvider.Id); - } -} \ No newline at end of file diff --git a/src/Artemis.UI/ArtemisBootstrapper.cs b/src/Artemis.UI/ArtemisBootstrapper.cs index 2e4a57937..1056070e1 100644 --- a/src/Artemis.UI/ArtemisBootstrapper.cs +++ b/src/Artemis.UI/ArtemisBootstrapper.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Reactive; +using System.Threading.Tasks; using Artemis.Core; using Artemis.Core.DryIoc; using Artemis.UI.DryIoc; @@ -11,6 +12,8 @@ using Artemis.UI.Shared.DataModelPicker; using Artemis.UI.Shared.DryIoc; using Artemis.UI.Shared.Services; using Artemis.VisualScripting.DryIoc; +using Artemis.WebClient.Updating; +using Artemis.WebClient.Updating.DryIoc; using Avalonia; using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; @@ -25,7 +28,7 @@ public static class ArtemisBootstrapper private static Container? _container; private static Application? _application; - public static IContainer Bootstrap(Application application, params IModule[] modules) + public static IContainer Bootstrap(Application application, Action? configureServices = null) { if (_application != null || _container != null) throw new ArtemisUIException("UI already bootstrapped"); @@ -33,18 +36,19 @@ public static class ArtemisBootstrapper Utilities.PrepareFirstLaunch(); _application = application; - _container = new Container(rules => rules.WithConcreteTypeDynamicRegistrations() - .WithoutThrowOnRegisteringDisposableTransient()); + _container = new Container(rules => rules + .WithMicrosoftDependencyInjectionRules() + .WithConcreteTypeDynamicRegistrations() + .WithoutThrowOnRegisteringDisposableTransient()); - new CoreModule().Load(_container); - new UIModule().Load(_container); - new SharedUIModule().Load(_container); - new NoStringDryIocModule().Load(_container); - foreach (IModule module in modules) - module.Load(_container); + _container.RegisterCore(); + _container.RegisterUI(); + _container.RegisterSharedUI(); + _container.RegisterUpdatingClient(); + _container.RegisterNoStringEvaluating(); + configureServices?.Invoke(_container); _container.UseDryIocDependencyResolver(); - return _container; } diff --git a/src/Artemis.UI/DryIoc/ContainerExtensions.cs b/src/Artemis.UI/DryIoc/ContainerExtensions.cs new file mode 100644 index 000000000..f4c484bec --- /dev/null +++ b/src/Artemis.UI/DryIoc/ContainerExtensions.cs @@ -0,0 +1,42 @@ +using System.Reflection; +using Artemis.UI.DryIoc.Factories; +using Artemis.UI.DryIoc.InstanceProviders; +using Artemis.UI.Screens; +using Artemis.UI.Screens.VisualScripting; +using Artemis.UI.Services.Interfaces; +using Artemis.UI.Shared; +using Artemis.UI.Shared.Services.NodeEditor; +using Artemis.UI.Shared.Services.ProfileEditor; +using Avalonia.Platform; +using Avalonia.Shared.PlatformSupport; +using DryIoc; + +namespace Artemis.UI.DryIoc; + +/// +/// Provides an extension method to register services onto a DryIoc . +/// +public static class UIContainerExtensions +{ + /// + /// Registers UI services into the container. + /// + /// The builder building the current container + public static void RegisterUI(this IContainer container) + { + Assembly[] thisAssembly = {typeof(UIContainerExtensions).Assembly}; + + container.RegisterInstance(new AssetLoader(), IfAlreadyRegistered.Throw); + container.Register(Reuse.Singleton); + + container.RegisterMany(thisAssembly, type => type.IsAssignableTo()); + container.RegisterMany(thisAssembly, type => type.IsAssignableTo(), ifAlreadyRegistered: IfAlreadyRegistered.Replace); + container.RegisterMany(thisAssembly, type => type.IsAssignableTo() && type.IsInterface); + container.RegisterMany(thisAssembly, type => type.IsAssignableTo() && type != typeof(PropertyVmFactory)); + + container.Register(Reuse.Singleton); + container.Register(Reuse.Singleton); + + container.RegisterMany(thisAssembly, type => type.IsAssignableTo(), Reuse.Singleton); + } +} \ No newline at end of file diff --git a/src/Artemis.UI/DryIoc/UiModule.cs b/src/Artemis.UI/DryIoc/UiModule.cs deleted file mode 100644 index 652f730d1..000000000 --- a/src/Artemis.UI/DryIoc/UiModule.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using Artemis.Core.DryIoc; -using Artemis.UI.DryIoc.Factories; -using Artemis.UI.DryIoc.InstanceProviders; -using Artemis.UI.Screens; -using Artemis.UI.Screens.VisualScripting; -using Artemis.UI.Services.Interfaces; -using Artemis.UI.Shared; -using Artemis.UI.Shared.Services.NodeEditor; -using Artemis.UI.Shared.Services.ProfileEditor; -using Avalonia.Platform; -using Avalonia.Shared.PlatformSupport; -using DryIoc; - -namespace Artemis.UI.DryIoc; - -public class UIModule : IModule -{ - public void Load(IRegistrator builder) - { - Assembly thisAssembly = typeof(UIModule).Assembly; - - builder.RegisterInstance(new AssetLoader(), IfAlreadyRegistered.Throw); - builder.Register(Reuse.Singleton); - - builder.RegisterMany(new[] { thisAssembly }, type => type.IsAssignableTo()); - builder.RegisterMany(new[] { thisAssembly }, type => type.IsAssignableTo(), ifAlreadyRegistered: IfAlreadyRegistered.Replace); - builder.RegisterMany(new[] { thisAssembly }, type => type.IsAssignableTo() && type.IsInterface); - builder.RegisterMany(new[] { thisAssembly }, type => type.IsAssignableTo() && type != typeof(PropertyVmFactory)); - - builder.Register(Reuse.Singleton); - builder.Register(Reuse.Singleton); - - builder.RegisterMany(new[] { thisAssembly }, type => type.IsAssignableTo(), Reuse.Singleton); - } -} \ No newline at end of file diff --git a/src/Artemis.VisualScripting/DryIoc/ContainerExtensions.cs b/src/Artemis.VisualScripting/DryIoc/ContainerExtensions.cs new file mode 100644 index 000000000..6e388f30d --- /dev/null +++ b/src/Artemis.VisualScripting/DryIoc/ContainerExtensions.cs @@ -0,0 +1,40 @@ +using DryIoc; +using Microsoft.Extensions.ObjectPool; +using NoStringEvaluating; +using NoStringEvaluating.Contract; +using NoStringEvaluating.Models.Values; +using NoStringEvaluating.Services.Cache; +using NoStringEvaluating.Services.Checking; +using NoStringEvaluating.Services.Parsing; +using NoStringEvaluating.Services.Parsing.NodeReaders; + +namespace Artemis.VisualScripting.DryIoc; + +/// +/// Provides an extension method to register services onto a DryIoc . +/// +public static class UIContainerExtensions +{ + /// + /// Registers NoStringEvaluating services into the container. + /// + /// The builder building the current container + public static void RegisterNoStringEvaluating(this IContainer container) + { + // Pooling + container.RegisterInstance(ObjectPool.Create>()); + container.RegisterInstance(ObjectPool.Create>()); + container.RegisterInstance(ObjectPool.Create()); + + // Parser + container.Register(Reuse.Singleton); + container.Register(Reuse.Singleton); + container.Register(Reuse.Singleton); + + // Checker + container.Register(Reuse.Singleton); + + // Evaluator + container.Register(Reuse.Singleton); + } +} \ No newline at end of file diff --git a/src/Artemis.VisualScripting/DryIoc/NoStringNinjectModule.cs b/src/Artemis.VisualScripting/DryIoc/NoStringNinjectModule.cs deleted file mode 100644 index 8d3563615..000000000 --- a/src/Artemis.VisualScripting/DryIoc/NoStringNinjectModule.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Artemis.Core.DryIoc; -using DryIoc; -using Microsoft.Extensions.ObjectPool; -using NoStringEvaluating; -using NoStringEvaluating.Contract; -using NoStringEvaluating.Models.Values; -using NoStringEvaluating.Services.Cache; -using NoStringEvaluating.Services.Checking; -using NoStringEvaluating.Services.Parsing; -using NoStringEvaluating.Services.Parsing.NodeReaders; - -namespace Artemis.VisualScripting.DryIoc; - -public class NoStringDryIocModule : IModule -{ - /// - public void Load(IRegistrator builder) - { - // Pooling - builder.RegisterInstance(ObjectPool.Create>()); - builder.RegisterInstance(ObjectPool.Create>()); - builder.RegisterInstance(ObjectPool.Create()); - - // Parser - builder.Register(Reuse.Singleton); - builder.Register(Reuse.Singleton); - builder.Register(Reuse.Singleton); - - // Checker - builder.Register(Reuse.Singleton); - - // Evaluator - builder.Register(Reuse.Singleton); - } -} \ No newline at end of file From 64decaf0c2e085c481f2032f572aa143839c0e11 Mon Sep 17 00:00:00 2001 From: Robert Date: Sat, 4 Feb 2023 23:32:14 +0100 Subject: [PATCH 2/6] Core - Refactor service registration pt 2 --- src/Artemis.Core/DryIoc/ContainerExtensions.cs | 2 +- src/Artemis.UI.Shared/DryIoc/ContainerExtensions.cs | 2 +- src/Artemis.UI/ArtemisBootstrapper.cs | 3 --- src/Artemis.UI/DryIoc/ContainerExtensions.cs | 4 ++-- src/Artemis.VisualScripting/DryIoc/ContainerExtensions.cs | 2 +- 5 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Artemis.Core/DryIoc/ContainerExtensions.cs b/src/Artemis.Core/DryIoc/ContainerExtensions.cs index 4f418d453..927f606a9 100644 --- a/src/Artemis.Core/DryIoc/ContainerExtensions.cs +++ b/src/Artemis.Core/DryIoc/ContainerExtensions.cs @@ -13,7 +13,7 @@ namespace Artemis.Core.DryIoc; /// /// Provides an extension method to register services onto a DryIoc . /// -public static class CoreContainerExtensions +public static class ContainerExtensions { /// /// Registers core services into the container. diff --git a/src/Artemis.UI.Shared/DryIoc/ContainerExtensions.cs b/src/Artemis.UI.Shared/DryIoc/ContainerExtensions.cs index cb7baef36..4c4711b02 100644 --- a/src/Artemis.UI.Shared/DryIoc/ContainerExtensions.cs +++ b/src/Artemis.UI.Shared/DryIoc/ContainerExtensions.cs @@ -7,7 +7,7 @@ namespace Artemis.UI.Shared.DryIoc; /// /// Provides an extension method to register services onto a DryIoc . /// -public static class UIContainerExtensions +public static class ContainerExtensions { /// /// Registers shared UI services into the container. diff --git a/src/Artemis.UI/ArtemisBootstrapper.cs b/src/Artemis.UI/ArtemisBootstrapper.cs index 1056070e1..1b47e8748 100644 --- a/src/Artemis.UI/ArtemisBootstrapper.cs +++ b/src/Artemis.UI/ArtemisBootstrapper.cs @@ -12,8 +12,6 @@ using Artemis.UI.Shared.DataModelPicker; using Artemis.UI.Shared.DryIoc; using Artemis.UI.Shared.Services; using Artemis.VisualScripting.DryIoc; -using Artemis.WebClient.Updating; -using Artemis.WebClient.Updating.DryIoc; using Avalonia; using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; @@ -44,7 +42,6 @@ public static class ArtemisBootstrapper _container.RegisterCore(); _container.RegisterUI(); _container.RegisterSharedUI(); - _container.RegisterUpdatingClient(); _container.RegisterNoStringEvaluating(); configureServices?.Invoke(_container); diff --git a/src/Artemis.UI/DryIoc/ContainerExtensions.cs b/src/Artemis.UI/DryIoc/ContainerExtensions.cs index f4c484bec..3e4caf226 100644 --- a/src/Artemis.UI/DryIoc/ContainerExtensions.cs +++ b/src/Artemis.UI/DryIoc/ContainerExtensions.cs @@ -16,7 +16,7 @@ namespace Artemis.UI.DryIoc; /// /// Provides an extension method to register services onto a DryIoc . /// -public static class UIContainerExtensions +public static class ContainerExtensions { /// /// Registers UI services into the container. @@ -24,7 +24,7 @@ public static class UIContainerExtensions /// The builder building the current container public static void RegisterUI(this IContainer container) { - Assembly[] thisAssembly = {typeof(UIContainerExtensions).Assembly}; + Assembly[] thisAssembly = {typeof(ContainerExtensions).Assembly}; container.RegisterInstance(new AssetLoader(), IfAlreadyRegistered.Throw); container.Register(Reuse.Singleton); diff --git a/src/Artemis.VisualScripting/DryIoc/ContainerExtensions.cs b/src/Artemis.VisualScripting/DryIoc/ContainerExtensions.cs index 6e388f30d..0377f56ec 100644 --- a/src/Artemis.VisualScripting/DryIoc/ContainerExtensions.cs +++ b/src/Artemis.VisualScripting/DryIoc/ContainerExtensions.cs @@ -13,7 +13,7 @@ namespace Artemis.VisualScripting.DryIoc; /// /// Provides an extension method to register services onto a DryIoc . /// -public static class UIContainerExtensions +public static class ContainerExtensions { /// /// Registers NoStringEvaluating services into the container. From 0200839a26300e4757005172bb1eaad8917da8a0 Mon Sep 17 00:00:00 2001 From: Diogo Trindade Date: Fri, 10 Feb 2023 11:06:52 +0000 Subject: [PATCH 3/6] Nodes - Added more HSV and HSL nodes --- .../Nodes/Color/HslSKColorNode.cs | 2 +- .../Nodes/Color/HsvSKColorNode.cs | 31 ++++++++++++++++ .../Nodes/Color/SkColorHsl.cs | 36 +++++++++++++++++++ .../Nodes/Color/SkColorHsv.cs | 36 +++++++++++++++++++ 4 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 src/Artemis.VisualScripting/Nodes/Color/HsvSKColorNode.cs create mode 100644 src/Artemis.VisualScripting/Nodes/Color/SkColorHsl.cs create mode 100644 src/Artemis.VisualScripting/Nodes/Color/SkColorHsv.cs diff --git a/src/Artemis.VisualScripting/Nodes/Color/HslSKColorNode.cs b/src/Artemis.VisualScripting/Nodes/Color/HslSKColorNode.cs index cba686c38..15ce66d84 100644 --- a/src/Artemis.VisualScripting/Nodes/Color/HslSKColorNode.cs +++ b/src/Artemis.VisualScripting/Nodes/Color/HslSKColorNode.cs @@ -3,7 +3,7 @@ using SkiaSharp; namespace Artemis.VisualScripting.Nodes.Color; -[Node("HSL Color", "Creates a color from hue, saturation and lightness values", "Color", InputType = typeof(Numeric), OutputType = typeof(SKColor))] +[Node("HSL Color", "Creates a color from hue, saturation and lightness numbers", "Color", InputType = typeof(Numeric), OutputType = typeof(SKColor))] public class HslSKColorNode : Node { public HslSKColorNode() diff --git a/src/Artemis.VisualScripting/Nodes/Color/HsvSKColorNode.cs b/src/Artemis.VisualScripting/Nodes/Color/HsvSKColorNode.cs new file mode 100644 index 000000000..2544ccec2 --- /dev/null +++ b/src/Artemis.VisualScripting/Nodes/Color/HsvSKColorNode.cs @@ -0,0 +1,31 @@ +using Artemis.Core; +using SkiaSharp; + +namespace Artemis.VisualScripting.Nodes.Color; + +[Node("HSV Color", "Creates a color from hue, saturation and value numbers", "Color", InputType = typeof(Numeric), OutputType = typeof(SKColor))] +public class HsvSKColorNode : Node +{ + public HsvSKColorNode() + { + H = CreateInputPin("H"); + S = CreateInputPin("S"); + V = CreateInputPin("V"); + Output = CreateOutputPin(); + } + + public InputPin H { get; set; } + public InputPin S { get; set; } + public InputPin V { get; set; } + public OutputPin Output { get; } + + #region Overrides of Node + + /// + public override void Evaluate() + { + Output.Value = SKColor.FromHsv(H.Value, S.Value, V.Value); + } + + #endregion +} \ No newline at end of file diff --git a/src/Artemis.VisualScripting/Nodes/Color/SkColorHsl.cs b/src/Artemis.VisualScripting/Nodes/Color/SkColorHsl.cs new file mode 100644 index 000000000..aaa1c6e26 --- /dev/null +++ b/src/Artemis.VisualScripting/Nodes/Color/SkColorHsl.cs @@ -0,0 +1,36 @@ +using Artemis.Core; +using SkiaSharp; + +namespace Artemis.VisualScripting.Nodes.Color; + +[Node("Color to HSL", "Outputs H, S and L values from a color", "Color", InputType = typeof(SKColor), OutputType = typeof(Numeric))] +public class SkColorHsl : Node +{ + + public SkColorHsl() + { + Input = CreateInputPin(); + H = CreateOutputPin("H"); + S = CreateOutputPin("S"); + L = CreateOutputPin("L"); + } + + public InputPin Input { get; } + public OutputPin H { get; } + public OutputPin S { get; } + public OutputPin L { get; } + + #region Overrides of Node + + /// + public override void Evaluate() + { + Input.Value.ToHsl(out float h, out float s, out float l); + + H.Value = h; + S.Value = s; + L.Value = l; + } + + #endregion +} \ No newline at end of file diff --git a/src/Artemis.VisualScripting/Nodes/Color/SkColorHsv.cs b/src/Artemis.VisualScripting/Nodes/Color/SkColorHsv.cs new file mode 100644 index 000000000..95a2dffb1 --- /dev/null +++ b/src/Artemis.VisualScripting/Nodes/Color/SkColorHsv.cs @@ -0,0 +1,36 @@ +using Artemis.Core; +using SkiaSharp; + +namespace Artemis.VisualScripting.Nodes.Color; + +[Node("Color to Hsv", "Outputs H, S and L values from a color", "Color", InputType = typeof(SKColor), OutputType = typeof(Numeric))] +public class SkColorHsv : Node +{ + + public SkColorHsv() + { + Input = CreateInputPin(); + H = CreateOutputPin("H"); + S = CreateOutputPin("S"); + V = CreateOutputPin("V"); + } + + public InputPin Input { get; } + public OutputPin H { get; } + public OutputPin S { get; } + public OutputPin V { get; } + + #region Overrides of Node + + /// + public override void Evaluate() + { + Input.Value.ToHsv(out float h, out float s, out float v); + + H.Value = h; + S.Value = s; + V.Value = v; + } + + #endregion +} \ No newline at end of file From f1c5b2c14f6120fed517f6c746882a4c5edb3e46 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 12 Feb 2023 17:44:03 +0100 Subject: [PATCH 4/6] Updated RGB.NET to stay in sync with plugins --- src/Artemis.Core/Artemis.Core.csproj | 6 +++--- src/Artemis.UI.Shared/Artemis.UI.Shared.csproj | 2 +- src/Artemis.UI/Artemis.UI.csproj | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Artemis.Core/Artemis.Core.csproj b/src/Artemis.Core/Artemis.Core.csproj index df21cdfd2..ee57c4987 100644 --- a/src/Artemis.Core/Artemis.Core.csproj +++ b/src/Artemis.Core/Artemis.Core.csproj @@ -42,9 +42,9 @@ - - - + + + diff --git a/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj b/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj index 09c2d5479..c8f440c29 100644 --- a/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj +++ b/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj @@ -20,7 +20,7 @@ - + diff --git a/src/Artemis.UI/Artemis.UI.csproj b/src/Artemis.UI/Artemis.UI.csproj index bf4ce5d0c..a9446ed2c 100644 --- a/src/Artemis.UI/Artemis.UI.csproj +++ b/src/Artemis.UI/Artemis.UI.csproj @@ -31,8 +31,8 @@ - - + + From 968b365a2935551d3efddb71a4bcb7ea5415866c Mon Sep 17 00:00:00 2001 From: Robert Date: Sun, 12 Feb 2023 21:27:46 +0100 Subject: [PATCH 5/6] Node editor - Fixed a crash when duplicating nodes with pin collections --- .../Services/NodeEditor/Commands/DuplicateNode.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Artemis.UI.Shared/Services/NodeEditor/Commands/DuplicateNode.cs b/src/Artemis.UI.Shared/Services/NodeEditor/Commands/DuplicateNode.cs index 8c60677b6..62340d3a6 100644 --- a/src/Artemis.UI.Shared/Services/NodeEditor/Commands/DuplicateNode.cs +++ b/src/Artemis.UI.Shared/Services/NodeEditor/Commands/DuplicateNode.cs @@ -56,7 +56,7 @@ public class DuplicateNode : INodeEditorCommand, IDisposable if (targetCollection == null) continue; while (targetCollection.Count() < sourceCollection.Count()) - targetCollection.CreatePin(); + targetCollection.Add(targetCollection.CreatePin()); } // Copy the storage From 7a5c018a3f9ea8c9e317bebaa5eee1ec250305b2 Mon Sep 17 00:00:00 2001 From: Robert Date: Sun, 12 Feb 2023 21:31:25 +0100 Subject: [PATCH 6/6] HSV Node - Fix name --- src/Artemis.VisualScripting/Nodes/Color/SkColorHsv.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Artemis.VisualScripting/Nodes/Color/SkColorHsv.cs b/src/Artemis.VisualScripting/Nodes/Color/SkColorHsv.cs index 95a2dffb1..a0e448cf4 100644 --- a/src/Artemis.VisualScripting/Nodes/Color/SkColorHsv.cs +++ b/src/Artemis.VisualScripting/Nodes/Color/SkColorHsv.cs @@ -3,7 +3,7 @@ using SkiaSharp; namespace Artemis.VisualScripting.Nodes.Color; -[Node("Color to Hsv", "Outputs H, S and L values from a color", "Color", InputType = typeof(SKColor), OutputType = typeof(Numeric))] +[Node("Color to HSV", "Outputs H, S and L values from a color", "Color", InputType = typeof(SKColor), OutputType = typeof(Numeric))] public class SkColorHsv : Node {