diff --git a/src/Volo.Abp.Core/Volo/Abp/Options/AbpOptionsFactory.cs b/src/Volo.Abp.Core/Volo/Abp/Options/AbpOptionsFactory.cs new file mode 100644 index 0000000000..ecbe0d8271 --- /dev/null +++ b/src/Volo.Abp.Core/Volo/Abp/Options/AbpOptionsFactory.cs @@ -0,0 +1,42 @@ +using System.Collections.Generic; +using Microsoft.Extensions.Options; + +namespace Volo.Abp.Options +{ + //TODO: Derive from OptionsFactory when this is released: https://github.com/aspnet/Options/pull/258 (or completely remove this!) + public class AbpOptionsFactory : IOptionsFactory where TOptions : class, new() + { + private readonly IEnumerable> _setups; + private readonly IEnumerable> _postConfigures; + + public AbpOptionsFactory(IEnumerable> setups, IEnumerable> postConfigures) + { + _setups = setups; + _postConfigures = postConfigures; + } + + public virtual TOptions Create(string name) + { + var options = new TOptions(); + + foreach (var setup in _setups) + { + if (setup is IConfigureNamedOptions namedSetup) + { + namedSetup.Configure(name, options); + } + else if (name == Microsoft.Extensions.Options.Options.DefaultName) + { + setup.Configure(options); + } + } + + foreach (var post in _postConfigures) + { + post.PostConfigure(name, options); + } + + return options; + } + } +} \ No newline at end of file