From a5577415a2e2d8cdc584be6dc304d8f7e5173796 Mon Sep 17 00:00:00 2001 From: Alexanderius Date: Sun, 15 May 2022 22:38:57 +0600 Subject: [PATCH] [#192] [add] initial impl --- .vscode/settings.json | 3 +- .../SimplifyWebRegistrationOverride.cs | 31 +++++++++++++++++++ .../SimplifyDIContainerProviderExtensions.cs | 16 ++++++++-- 3 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 src/Simplify.Web/Bootstrapper/SimplifyWebRegistrationOverride.cs diff --git a/.vscode/settings.json b/.vscode/settings.json index e78665be..928265f0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,6 +7,7 @@ "cref", "HOSTINGSTARTUPASSEMBLIES", "OWIN", - "Redirector" + "Redirector", + "registrator" ] } \ No newline at end of file diff --git a/src/Simplify.Web/Bootstrapper/SimplifyWebRegistrationOverride.cs b/src/Simplify.Web/Bootstrapper/SimplifyWebRegistrationOverride.cs new file mode 100644 index 00000000..3961f847 --- /dev/null +++ b/src/Simplify.Web/Bootstrapper/SimplifyWebRegistrationOverride.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using Simplify.DI; + +namespace Simplify.Web.Bootstrapper +{ + public class SimplifyWebRegistrationOverride + { + private IList> Actions = new List>(); + + public SimplifyWebRegistrationOverride OverrideConfiguration(Action registrator) + { + Actions.Add(registrator); + + return this; + } + + public SimplifyWebRegistrationOverride OverrideControllerExecutor(Action registrator) + { + Actions.Add(registrator); + + return this; + } + + public void RegisterActions(IDIRegistrator registrator) + { + foreach (var item in Actions) + item.Invoke(registrator); + } + } +} \ No newline at end of file diff --git a/src/Simplify.Web/SimplifyDIContainerProviderExtensions.cs b/src/Simplify.Web/SimplifyDIContainerProviderExtensions.cs index c98f9232..f5691c26 100644 --- a/src/Simplify.Web/SimplifyDIContainerProviderExtensions.cs +++ b/src/Simplify.Web/SimplifyDIContainerProviderExtensions.cs @@ -1,4 +1,5 @@ -using Simplify.DI; +using System; +using Simplify.DI; using Simplify.Web.Bootstrapper; namespace Simplify.Web; @@ -12,11 +13,20 @@ public static class SimplifyDIContainerProviderExtensions /// Registers Simplify.Web types and controllers and use this container as current for Simplify.Web. /// /// The container provider. - public static IDIContainerProvider RegisterSimplifyWeb(this IDIContainerProvider containerProvider) + public static IDIContainerProvider RegisterSimplifyWeb(this IDIContainerProvider containerProvider, Action? registrationOverride = null) { BootstrapperFactory.ContainerProvider = containerProvider; - BootstrapperFactory.CreateBootstrapper().Register(); + if (registrationOverride != null) + { + var overrideSettings = new SimplifyWebRegistrationOverride(); + + registrationOverride.Invoke(overrideSettings); + + overrideSettings.RegisterActions(BootstrapperFactory.ContainerProvider); + } + else + BootstrapperFactory.CreateBootstrapper().Register(); return containerProvider; }