mirror of https://github.com/abpframework/abp.git
8 changed files with 85 additions and 30 deletions
@ -0,0 +1,27 @@ |
|||||
|
using System; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Options; |
||||
|
|
||||
|
namespace Microsoft.Extensions.DependencyInjection |
||||
|
{ |
||||
|
public static class ServiceCollectionPreConfigureExtensions |
||||
|
{ |
||||
|
public static IServiceCollection PreConfigure<TOptions>(this IServiceCollection services, Action<TOptions> optionsAction) |
||||
|
{ |
||||
|
services.GetPreConfigureActions<TOptions>().Add(optionsAction); |
||||
|
return services; |
||||
|
} |
||||
|
|
||||
|
public static PreConfigureActionList<TOptions> GetPreConfigureActions<TOptions>(this IServiceCollection services) |
||||
|
{ |
||||
|
var actionList = services.GetSingletonInstanceOrNull<IObjectAccessor<PreConfigureActionList<TOptions>>>()?.Value; |
||||
|
if (actionList == null) |
||||
|
{ |
||||
|
actionList = new PreConfigureActionList<TOptions>(); |
||||
|
services.AddObjectAccessor(actionList); |
||||
|
} |
||||
|
|
||||
|
return actionList; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace Volo.Abp.Options |
||||
|
{ |
||||
|
public class PreConfigureActionList<TOptions> : List<Action<TOptions>> |
||||
|
{ |
||||
|
public void Configure(TOptions options) |
||||
|
{ |
||||
|
foreach (var action in this) |
||||
|
{ |
||||
|
action(options); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue