Skip to content

Commit

Permalink
[#192] [add] initial impl
Browse files Browse the repository at this point in the history
  • Loading branch information
i4004 committed May 15, 2022
1 parent 1446cc0 commit a557741
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"cref",
"HOSTINGSTARTUPASSEMBLIES",
"OWIN",
"Redirector"
"Redirector",
"registrator"
]
}
31 changes: 31 additions & 0 deletions src/Simplify.Web/Bootstrapper/SimplifyWebRegistrationOverride.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using Simplify.DI;

namespace Simplify.Web.Bootstrapper
{
public class SimplifyWebRegistrationOverride
{
private IList<Action<IDIRegistrator>> Actions = new List<Action<IDIRegistrator>>();

public SimplifyWebRegistrationOverride OverrideConfiguration(Action<IDIRegistrator> registrator)
{
Actions.Add(registrator);

return this;
}

public SimplifyWebRegistrationOverride OverrideControllerExecutor(Action<IDIRegistrator> registrator)
{
Actions.Add(registrator);

return this;
}

public void RegisterActions(IDIRegistrator registrator)
{
foreach (var item in Actions)
item.Invoke(registrator);
}
}
}
16 changes: 13 additions & 3 deletions src/Simplify.Web/SimplifyDIContainerProviderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Simplify.DI;
using System;
using Simplify.DI;
using Simplify.Web.Bootstrapper;

namespace Simplify.Web;
Expand All @@ -12,11 +13,20 @@ public static class SimplifyDIContainerProviderExtensions
/// Registers Simplify.Web types and controllers and use this container as current for Simplify.Web.
/// </summary>
/// <param name="containerProvider">The container provider.</param>
public static IDIContainerProvider RegisterSimplifyWeb(this IDIContainerProvider containerProvider)
public static IDIContainerProvider RegisterSimplifyWeb(this IDIContainerProvider containerProvider, Action<SimplifyWebRegistrationOverride>? 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;
}
Expand Down

0 comments on commit a557741

Please sign in to comment.