Refactors Configs and how it acquires a factory, re-internalizes Umbraco.Configuration classes
This commit is contained in:
@@ -124,14 +124,14 @@ namespace Umbraco.Core.Composing
|
||||
builder.RegisterWith(_register);
|
||||
_builders.Clear(); // no point keep them around
|
||||
|
||||
Configs.RegisterWith(_register);
|
||||
|
||||
IFactory factory = null;
|
||||
|
||||
Configs.RegisterWith(_register, () => factory);
|
||||
|
||||
// ReSharper disable once AccessToModifiedClosure -- on purpose
|
||||
_register.Register(_ => factory, Lifetime.Singleton);
|
||||
factory = _register.CreateFactory();
|
||||
|
||||
Configs.Factory = factory;
|
||||
return factory;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,16 +15,6 @@ namespace Umbraco.Core.Configuration
|
||||
{
|
||||
private readonly Func<string, object> _configGetter;
|
||||
|
||||
public IFactory Factory
|
||||
{
|
||||
get => _factory;
|
||||
set
|
||||
{
|
||||
if(!(_factory is null)) throw new InvalidOperationException("Factory cannot be set multiple times");
|
||||
_factory = value;
|
||||
}
|
||||
}
|
||||
|
||||
public Configs(Func<string, object> configGetter)
|
||||
{
|
||||
_configGetter = configGetter;
|
||||
@@ -32,7 +22,7 @@ namespace Umbraco.Core.Configuration
|
||||
|
||||
private readonly Dictionary<Type, Lazy<object>> _configs = new Dictionary<Type, Lazy<object>>();
|
||||
private Dictionary<Type, Action<IRegister>> _registerings = new Dictionary<Type, Action<IRegister>>();
|
||||
private IFactory _factory;
|
||||
private Lazy<IFactory> _factory;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a configuration.
|
||||
@@ -76,7 +66,7 @@ namespace Umbraco.Core.Configuration
|
||||
|
||||
_configs[typeOfConfig] = new Lazy<object>(() =>
|
||||
{
|
||||
if (!(Factory is null)) return Factory.GetInstance<TConfig>();
|
||||
if (!(_factory is null)) return _factory.Value.GetInstance<TConfig>();
|
||||
throw new InvalidOperationException($"Cannot get configuration of type {typeOfConfig} during composition.");
|
||||
});
|
||||
_registerings[typeOfConfig] = register => register.Register(configFactory, Lifetime.Singleton);
|
||||
@@ -109,12 +99,14 @@ namespace Umbraco.Core.Configuration
|
||||
/// <summary>
|
||||
/// Registers configurations in a register.
|
||||
/// </summary>
|
||||
public void RegisterWith(IRegister register)
|
||||
public void RegisterWith(IRegister register, Func<IFactory> factory)
|
||||
{
|
||||
// do it only once
|
||||
if (_registerings == null)
|
||||
throw new InvalidOperationException("Configurations have already been registered.");
|
||||
|
||||
_factory = new Lazy<IFactory>(factory);
|
||||
|
||||
register.Register(this);
|
||||
|
||||
foreach (var registering in _registerings.Values)
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Umbraco.Core.Configuration
|
||||
/// <summary>
|
||||
/// Defines a configuration section that contains inner text that is comma delimited
|
||||
/// </summary>
|
||||
public class CommaDelimitedConfigurationElement : InnerTextConfigurationElement<CommaDelimitedStringCollection>, IEnumerable<string>
|
||||
internal class CommaDelimitedConfigurationElement : InnerTextConfigurationElement<CommaDelimitedStringCollection>, IEnumerable<string>
|
||||
{
|
||||
public override CommaDelimitedStringCollection Value
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Umbraco.Core.Configuration
|
||||
/// {element}MyValue{/element} instead of as attribute values.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class InnerTextConfigurationElement<T> : RawXmlConfigurationElement
|
||||
internal class InnerTextConfigurationElement<T> : RawXmlConfigurationElement
|
||||
{
|
||||
public InnerTextConfigurationElement()
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace Umbraco.Core.Configuration
|
||||
/// <summary>
|
||||
/// Used for specifying default values for comma delimited config
|
||||
/// </summary>
|
||||
public class OptionalCommaDelimitedConfigurationElement : CommaDelimitedConfigurationElement
|
||||
internal class OptionalCommaDelimitedConfigurationElement : CommaDelimitedConfigurationElement
|
||||
{
|
||||
private readonly CommaDelimitedConfigurationElement _wrapped;
|
||||
private readonly string[] _defaultValue;
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Umbraco.Core.Configuration
|
||||
/// A configuration section that simply exposes the entire raw xml of the section itself which inheritors can use
|
||||
/// to do with as they please.
|
||||
/// </summary>
|
||||
public abstract class RawXmlConfigurationElement : ConfigurationElement
|
||||
internal abstract class RawXmlConfigurationElement : ConfigurationElement
|
||||
{
|
||||
protected RawXmlConfigurationElement()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user