Simplified more config

This commit is contained in:
Bjarke Berg
2020-03-13 20:37:10 +01:00
parent 263b986ced
commit c1f42a9258
25 changed files with 127 additions and 156 deletions
+12 -17
View File
@@ -1,17 +1,14 @@
using System.Configuration;
using Umbraco.Configuration;
using Umbraco.Configuration.Implementations;
using Umbraco.Core.Configuration.HealthChecks;
using Umbraco.Core.Configuration.Implementations;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
namespace Umbraco.Core.Configuration
{
public class ConfigsFactory : IConfigsFactory
{
public IHostingSettings HostingSettings { get; } = new HostingSettings();
public ICoreDebug CoreDebug { get; } = new CoreDebug();
public IMachineKeyConfig MachineKeyConfig { get; } = new MachineKeyConfig();
public IIndexCreatorSettings IndexCreatorSettings { get; } = new IndexCreatorSettings();
@@ -30,28 +27,27 @@ namespace Umbraco.Core.Configuration
public IMemberPasswordConfiguration MemberPasswordConfigurationSettings { get; } = new MemberPasswordConfigurationSettings();
public IContentSettings ContentSettings { get; } = new ContentSettings();
public IGlobalSettings GlobalSettings { get; } = new GlobalSettings();
public IHealthChecks HealthChecksSettings { get; } = new HealthChecksSettings();
public IConnectionStrings ConnectionStrings { get; } = new ConnectionStrings();
public IModelsBuilderConfig ModelsBuilderConfig { get; } = new ModelsBuilderConfig();
public Configs Create()
{
var configs = new Configs(section => ConfigurationManager.GetSection(section));
var configs = new Configs();
configs.Add<IGlobalSettings>(() => GlobalSettings);
configs.Add(() => HostingSettings);
configs.Add<IHealthChecks>("umbracoConfiguration/HealthChecks");
configs.Add(() => CoreDebug);
configs.Add(() => MachineKeyConfig);
configs.Add<IConnectionStrings>(() => new ConnectionStrings());
configs.Add<IModelsBuilderConfig>(() => new ModelsBuilderConfig());
configs.Add<IHostingSettings>(() => HostingSettings);
configs.Add<IHealthChecks>(() => HealthChecksSettings);
configs.Add<ICoreDebug>(() => CoreDebug);
configs.Add<IMachineKeyConfig>(() => MachineKeyConfig);
configs.Add<IConnectionStrings>(() => ConnectionStrings);
configs.Add<IModelsBuilderConfig>(() => ModelsBuilderConfig);
configs.Add<IIndexCreatorSettings>(() => IndexCreatorSettings);
configs.Add<INuCacheSettings>(() => NuCacheSettings);
configs.Add<ITypeFinderSettings>(() => TypeFinderSettings);
configs.Add<IRuntimeSettings>(() => RuntimeSettings);
configs.Add<IActiveDirectorySettings>(() => ActiveDirectorySettings);
configs.Add<IExceptionFilterSettings>(() => ExceptionFilterSettings);
configs.Add<ITourSettings>(() => TourSettings);
configs.Add<ILoggingSettings>(() => LoggingSettings);
configs.Add<IKeepAliveSettings>(() => KeepAliveSettings);
@@ -62,7 +58,6 @@ namespace Umbraco.Core.Configuration
configs.Add<IMemberPasswordConfiguration>(() => MemberPasswordConfigurationSettings);
configs.Add<IContentSettings>(() => ContentSettings);
configs.AddCoreConfigs();
return configs;
}
}
@@ -1,10 +1,9 @@
using System;
using System.Collections.Generic;
using System.Configuration;
namespace Umbraco.Core.Configuration.HealthChecks
{
public class HealthChecksSection : ConfigurationSection, IHealthChecks
public class HealthChecksSection : ConfigurationSection
{
private const string DisabledChecksKey = "disabledChecks";
private const string NotificationSettingsKey = "notificationSettings";
@@ -21,14 +20,5 @@ namespace Umbraco.Core.Configuration.HealthChecks
get { return ((HealthCheckNotificationSettingsElement)(base[NotificationSettingsKey])); }
}
IEnumerable<IDisabledHealthCheck> IHealthChecks.DisabledChecks
{
get { return DisabledChecks; }
}
IHealthCheckNotificationSettings IHealthChecks.NotificationSettings
{
get { return NotificationSettings; }
}
}
}
@@ -7,7 +7,7 @@ namespace Umbraco.Configuration.Implementations
{
private UmbracoSettingsSection _umbracoSettingsSection;
public UmbracoSettingsSection UmbracoSettingsSection
protected UmbracoSettingsSection UmbracoSettingsSection
{
get
{
@@ -0,0 +1,26 @@
using System.Collections.Generic;
using System.Configuration;
using Umbraco.Core.Configuration.HealthChecks;
namespace Umbraco.Core.Configuration.Implementations
{
public class HealthChecksSettings : IHealthChecks
{
private HealthChecksSection _healthChecksSection;
private HealthChecksSection HealthChecksSection
{
get
{
if (_healthChecksSection is null)
{
_healthChecksSection = ConfigurationManager.GetSection("umbracoConfiguration/HealthChecks") as HealthChecksSection;
}
return _healthChecksSection;
}
}
public IEnumerable<IDisabledHealthCheck> DisabledChecks => HealthChecksSection.DisabledChecks;
public IHealthCheckNotificationSettings NotificationSettings => HealthChecksSection.NotificationSettings;
}
}
+1 -1
View File
@@ -135,7 +135,7 @@ namespace Umbraco.Core.Composing
IFactory factory = null;
Configs.RegisterWith(_register, () => factory);
Configs.RegisterWith(_register);
// ReSharper disable once AccessToModifiedClosure -- on purpose
_register.Register(_ => factory, Lifetime.Singleton);
+1 -55
View File
@@ -13,16 +13,8 @@ namespace Umbraco.Core.Configuration
/// </remarks>
public class Configs
{
private readonly Func<string, object> _configSectionResolver;
public Configs(Func<string, object> configSectionResolver)
{
_configSectionResolver = configSectionResolver ?? throw new ArgumentNullException(nameof(configSectionResolver));
}
private readonly Dictionary<Type, Lazy<object>> _configs = new Dictionary<Type, Lazy<object>>();
private Dictionary<Type, Action<IRegister>> _registerings = new Dictionary<Type, Action<IRegister>>();
private Lazy<IFactory> _factory;
/// <summary>
/// Gets a configuration.
@@ -52,61 +44,15 @@ namespace Umbraco.Core.Configuration
_registerings[typeOfConfig] = register => register.Register(_ => (TConfig) lazyConfigFactory.Value, Lifetime.Singleton);
}
/// <summary>
/// Adds a configuration, provided by a factory.
/// </summary>
public void Add<TConfig>(Func<IFactory, TConfig> configFactory)
where TConfig : class
{
// make sure it is not too late
if (_registerings == null)
throw new InvalidOperationException("Configurations have already been registered.");
var typeOfConfig = typeof(TConfig);
_configs[typeOfConfig] = new Lazy<object>(() =>
{
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);
}
/// <summary>
/// Adds a configuration, provided by a configuration section.
/// </summary>
public void Add<TConfig>(string sectionName)
where TConfig : class
{
Add(() => GetConfig<TConfig>(sectionName));
}
private TConfig GetConfig<TConfig>(string sectionName)
where TConfig : class
{
// note: need to use SafeCallContext here because ConfigurationManager.GetSection ends up getting AppDomain.Evidence
// which will want to serialize the call context including anything that is in there - what a mess!
using (new SafeCallContext())
{
if ((_configSectionResolver(sectionName) is TConfig config))
return config;
var ex = new InvalidOperationException($"Could not get configuration section \"{sectionName}\" from config files.");
throw ex;
}
}
/// <summary>
/// Registers configurations in a register.
/// </summary>
public void RegisterWith(IRegister register, Func<IFactory> factory)
public void RegisterWith(IRegister register)
{
// 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)
@@ -1,13 +1,7 @@
using System.IO;
using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.Grid;
using Umbraco.Core.Configuration.HealthChecks;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.Manifest;
namespace Umbraco.Core
{
@@ -45,22 +39,8 @@ namespace Umbraco.Core
public static IHealthChecks HealthChecks(this Configs configs)
=> configs.GetConfig<IHealthChecks>();
public static IGridConfig Grids(this Configs configs)
=> configs.GetConfig<IGridConfig>();
public static ICoreDebug CoreDebug(this Configs configs)
=> configs.GetConfig<ICoreDebug>();
public static void AddCoreConfigs(this Configs configs)
{
// GridConfig depends on runtime caches, manifest parsers... and cannot be available during composition
configs.Add<IGridConfig>(factory => new GridConfig(
factory.GetInstance<ILogger>(),
factory.GetInstance<AppCaches>(),
new DirectoryInfo(factory.GetInstance<IIOHelper>().MapPath(Constants.SystemDirectories.Config)),
factory.GetInstance<IManifestParser>(),
factory.GetInstance<IRuntimeState>().Debug));
}
}
}
@@ -1,15 +1,18 @@
using System.IO;
using Umbraco.Core.Cache;
using Umbraco.Core.Hosting;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.Manifest;
using Umbraco.Core.Serialization;
namespace Umbraco.Core.Configuration.Grid
{
public class GridConfig : IGridConfig
{
public GridConfig(ILogger logger, AppCaches appCaches, DirectoryInfo configFolder, IManifestParser manifestParser, bool isDebug)
public GridConfig(AppCaches appCaches, IIOHelper ioHelper, IManifestParser manifestParser, IJsonSerializer jsonSerializer, IHostingEnvironment hostingEnvironment)
{
EditorsConfig = new GridEditorsConfig(logger, appCaches, configFolder, manifestParser, isDebug);
EditorsConfig = new GridEditorsConfig(appCaches, ioHelper, manifestParser, jsonSerializer, hostingEnvironment.IsDebugMode);
}
public IGridEditorsConfig EditorsConfig { get; }
@@ -1,27 +1,30 @@
using System;
using System.Collections.Generic;
using System.IO;
using Umbraco.Composing;
using Umbraco.Core.Cache;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.Manifest;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Serialization;
namespace Umbraco.Core.Configuration.Grid
{
internal class GridEditorsConfig : IGridEditorsConfig
{
private readonly ILogger _logger;
private readonly AppCaches _appCaches;
private readonly DirectoryInfo _configFolder;
private readonly IIOHelper _ioHelper;
private readonly IManifestParser _manifestParser;
private readonly bool _isDebug;
private readonly IJsonSerializer _jsonSerializer;
public GridEditorsConfig(ILogger logger, AppCaches appCaches, DirectoryInfo configFolder, IManifestParser manifestParser, bool isDebug)
public GridEditorsConfig(AppCaches appCaches, IIOHelper ioHelper, IManifestParser manifestParser,IJsonSerializer jsonSerializer, bool isDebug)
{
_logger = logger;
_appCaches = appCaches;
_configFolder = configFolder;
_ioHelper = ioHelper;
_manifestParser = manifestParser;
_jsonSerializer = jsonSerializer;
_isDebug = isDebug;
}
@@ -31,19 +34,20 @@ namespace Umbraco.Core.Configuration.Grid
{
List<IGridEditorConfig> GetResult()
{
var configFolder = new DirectoryInfo(_ioHelper.MapPath(Constants.SystemDirectories.Config));
var editors = new List<IGridEditorConfig>();
var gridConfig = Path.Combine(_configFolder.FullName, "grid.editors.config.js");
var gridConfig = Path.Combine(configFolder.FullName, "grid.editors.config.js");
if (File.Exists(gridConfig))
{
var sourceString = File.ReadAllText(gridConfig);
try
{
editors.AddRange(_manifestParser.ParseGridEditors(sourceString));
editors.AddRange(_jsonSerializer.Deserialize<IEnumerable<GridEditor>>(sourceString));
}
catch (Exception ex)
{
_logger.Error<GridEditorsConfig>(ex, "Could not parse the contents of grid.editors.config.js into a JSON array '{Json}", sourceString);
Current.Logger.Error<GridEditorsConfig>(ex, "Could not parse the contents of grid.editors.config.js into a JSON array '{Json}", sourceString);
}
}
@@ -63,7 +67,6 @@ namespace Umbraco.Core.Configuration.Grid
return result;
}
}
}
}
@@ -17,7 +17,5 @@ namespace Umbraco.Core.Manifest
/// Parses a manifest.
/// </summary>
PackageManifest ParseManifest(string text);
IEnumerable<GridEditor> ParseGridEditors(string text);
}
}
@@ -220,11 +220,5 @@ namespace Umbraco.Core.Manifest
return manifest;
}
// purely for tests
public IEnumerable<GridEditor> ParseGridEditors(string text)
{
return _jsonSerializer.Deserialize<IEnumerable<GridEditor>>(text);
}
}
}
@@ -27,8 +27,9 @@ namespace Umbraco.Core.Persistence
// TODO: this class needs not be disposable!
internal class UmbracoDatabaseFactory : DisposableObjectSlim, IUmbracoDatabaseFactory
{
private readonly Configs _configs;
private readonly IDbProviderFactoryCreator _dbProviderFactoryCreator;
private readonly IGlobalSettings _globalSettings;
private readonly IConnectionStrings _connectionStrings;
private readonly Lazy<IMapperCollection> _mappers;
private readonly ILogger _logger;
@@ -71,27 +72,28 @@ namespace Umbraco.Core.Persistence
/// Initializes a new instance of the <see cref="UmbracoDatabaseFactory"/>.
/// </summary>
/// <remarks>Used by core runtime.</remarks>
public UmbracoDatabaseFactory(ILogger logger, Lazy<IMapperCollection> mappers, Configs configs, IDbProviderFactoryCreator dbProviderFactoryCreator)
: this(Constants.System.UmbracoConnectionName, logger, mappers, configs, dbProviderFactoryCreator)
public UmbracoDatabaseFactory(ILogger logger, IGlobalSettings globalSettings, IConnectionStrings connectionStrings, Lazy<IMapperCollection> mappers,IDbProviderFactoryCreator dbProviderFactoryCreator)
: this(Constants.System.UmbracoConnectionName, globalSettings, connectionStrings, logger, mappers, dbProviderFactoryCreator)
{
_configs = configs;
}
/// <summary>
/// Initializes a new instance of the <see cref="UmbracoDatabaseFactory"/>.
/// </summary>
/// <remarks>Used by the other ctor and in tests.</remarks>
public UmbracoDatabaseFactory(string connectionStringName, ILogger logger, Lazy<IMapperCollection> mappers, Configs configs, IDbProviderFactoryCreator dbProviderFactoryCreator)
public UmbracoDatabaseFactory(string connectionStringName, IGlobalSettings globalSettings, IConnectionStrings connectionStrings, ILogger logger, Lazy<IMapperCollection> mappers, IDbProviderFactoryCreator dbProviderFactoryCreator)
{
if (connectionStringName == null) throw new ArgumentNullException(nameof(connectionStringName));
if (string.IsNullOrWhiteSpace(connectionStringName)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(connectionStringName));
_globalSettings = globalSettings;
_connectionStrings = connectionStrings;
_mappers = mappers ?? throw new ArgumentNullException(nameof(mappers));
_configs = configs;
_dbProviderFactoryCreator = dbProviderFactoryCreator ?? throw new ArgumentNullException(nameof(dbProviderFactoryCreator));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
var settings = configs.ConnectionStrings()[connectionStringName];
var settings = connectionStrings[connectionStringName];
if (settings == null)
{
@@ -161,7 +163,7 @@ namespace Umbraco.Core.Persistence
{
// replace NPoco database type by a more efficient one
var setting = _configs.Global().DatabaseFactoryServerVersion;
var setting = _globalSettings.DatabaseFactoryServerVersion;
var fromSettings = false;
if (setting.IsNullOrWhiteSpace() || !setting.StartsWith("SqlServer.")
@@ -1,12 +1,15 @@
using System;
using System.IO;
using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
using Umbraco.Core.Composing.CompositionExtensions;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.Grid;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Dashboards;
using Umbraco.Core.Hosting;
using Umbraco.Core.Dictionary;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.Manifest;
using Umbraco.Core.Migrations;
@@ -169,6 +172,9 @@ namespace Umbraco.Core.Runtime
// will be injected in controllers when needed to invoke rest endpoints on Our
composition.RegisterUnique<IInstallationService, InstallationService>();
composition.RegisterUnique<IUpgradeService, UpgradeService>();
// Grid config is not a real config file as we know them
composition.RegisterUnique<IGridConfig, GridConfig>();
}
}
}
@@ -27,6 +27,8 @@ namespace Umbraco.Core.Runtime
private IFactory _factory;
private RuntimeState _state;
private readonly IUmbracoBootPermissionChecker _umbracoBootPermissionChecker;
private readonly IGlobalSettings _globalSettings;
private readonly IConnectionStrings _connectionStrings;
public CoreRuntime(
@@ -54,6 +56,10 @@ namespace Umbraco.Core.Runtime
Logger = logger;
MainDom = mainDom;
_globalSettings = Configs.Global();
_connectionStrings = configs.ConnectionStrings();
// runtime state
// beware! must use '() => _factory.GetInstance<T>()' and NOT '_factory.GetInstance<T>'
// as the second one captures the current value (null) and therefore fails
@@ -412,7 +418,7 @@ namespace Umbraco.Core.Runtime
/// </summary>
/// <remarks>This is strictly internal, for tests only.</remarks>
protected internal virtual IUmbracoDatabaseFactory GetDatabaseFactory()
=> new UmbracoDatabaseFactory(Logger, new Lazy<IMapperCollection>(() => _factory.GetInstance<IMapperCollection>()), Configs, DbProviderFactoryCreator);
=> new UmbracoDatabaseFactory(Logger, _globalSettings, _connectionStrings, new Lazy<IMapperCollection>(() => _factory.GetInstance<IMapperCollection>()), DbProviderFactoryCreator);
#endregion
@@ -28,16 +28,18 @@ namespace Umbraco.Core.Runtime
private bool _hasError;
private object _locker = new object();
public SqlMainDomLock(ILogger logger, Configs configs, IDbProviderFactoryCreator dbProviderFactoryCreator)
public SqlMainDomLock(ILogger logger, IGlobalSettings globalSettings, IConnectionStrings connectionStrings, IDbProviderFactoryCreator dbProviderFactoryCreator)
{
// unique id for our appdomain, this is more unique than the appdomain id which is just an INT counter to its safer
_lockId = Guid.NewGuid().ToString();
_logger = logger;
_dbFactory = new UmbracoDatabaseFactory(
Constants.System.UmbracoConnectionName,
globalSettings,
connectionStrings,
_logger,
new Lazy<IMapperCollection>(() => new MapperCollection(Enumerable.Empty<BaseMapper>())),
configs, dbProviderFactoryCreator
dbProviderFactoryCreator
);
}
@@ -31,7 +31,7 @@ namespace Umbraco.ModelsBuilder.Embedded.Compose
composition.RegisterUnique<LiveModelsProvider>();
composition.RegisterUnique<OutOfDateModelsStatus>();
composition.RegisterUnique<ModelsGenerationError>();
if (composition.Configs.ModelsBuilder().ModelsMode == ModelsMode.PureLive)
ComposeForLiveModels(composition);
else if (composition.Configs.ModelsBuilder().EnableFactory)
@@ -33,7 +33,7 @@ namespace Umbraco.Tests.Components
var logger = Mock.Of<ILogger>();
var typeFinder = TestHelper.GetTypeFinder();
var f = new UmbracoDatabaseFactory(logger, new Lazy<IMapperCollection>(() => new MapperCollection(Enumerable.Empty<BaseMapper>())), TestHelper.GetConfigs(), TestHelper.DbProviderFactoryCreator);
var f = new UmbracoDatabaseFactory(logger, SettingsForTests.GetDefaultGlobalSettings(), Mock.Of<IConnectionStrings>(), new Lazy<IMapperCollection>(() => new MapperCollection(Enumerable.Empty<BaseMapper>())), TestHelper.DbProviderFactoryCreator);
var fs = new FileSystems(mock.Object, logger, TestHelper.IOHelper, SettingsForTests.GenerateMockGlobalSettings());
var coreDebug = Mock.Of<ICoreDebug>();
var mediaFileSystem = Mock.Of<IMediaFileSystem>();
@@ -37,7 +37,9 @@ namespace Umbraco.Tests.Persistence
_sqlSyntaxProviders = new[] { (ISqlSyntaxProvider) _sqlCeSyntaxProvider };
_logger = Mock.Of<ILogger>();
_umbracoVersion = TestHelper.GetUmbracoVersion();
_databaseFactory = new UmbracoDatabaseFactory(_logger, new Lazy<IMapperCollection>(() => Mock.Of<IMapperCollection>()), TestHelper.GetConfigs(), TestHelper.DbProviderFactoryCreator);
var globalSettings = TestHelper.GetConfigs().Global();
var connectionStrings = TestHelper.GetConfigs().ConnectionStrings();
_databaseFactory = new UmbracoDatabaseFactory(_logger, globalSettings, connectionStrings, new Lazy<IMapperCollection>(() => Mock.Of<IMapperCollection>()), TestHelper.DbProviderFactoryCreator);
}
[TearDown]
@@ -14,6 +14,7 @@ using Umbraco.Tests.TestHelpers.Entities;
using Umbraco.Web;
using Umbraco.Web.Routing;
using Umbraco.Tests.Common;
using SettingsForTests = Umbraco.Tests.TestHelpers.SettingsForTests;
namespace Umbraco.Tests.Routing
{
@@ -77,7 +78,7 @@ namespace Umbraco.Tests.Routing
content.Path = "-1,1046";
content.Published = true;
var umbracoSettings = Current.Configs.RequestHandler();
var umbracoSettings = SettingsForTests.GenerateMockRequestHandlerSettings();
var umbContext = GetUmbracoContext("http://localhost:8000");
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbContext);
@@ -122,7 +123,7 @@ namespace Umbraco.Tests.Routing
child.Path = "-1,1046,1173";
child.Published = true;
var umbracoSettings = Current.Configs.RequestHandler();
var umbracoSettings = SettingsForTests.GenerateMockRequestHandlerSettings();
var umbContext = GetUmbracoContext("http://localhost:8000");
@@ -90,16 +90,17 @@ namespace Umbraco.Tests.Runtimes
private static readonly IIOHelper _ioHelper = TestHelper.IOHelper;
private static readonly IProfiler _profiler = new TestProfiler();
private static readonly Configs _configs = GetConfigs();
private static readonly IGlobalSettings _globalSettings = _configs.Global();
private static readonly IHostingSettings _hostingSettings = _configs.Hosting();
private static readonly IGlobalSettings _globalSettings = SettingsForTests.GetDefaultGlobalSettings();
private static readonly IHostingSettings _hostingSettings = SettingsForTests.GetDefaultHostingSettings();
private static readonly IContentSettings _contentSettings = SettingsForTests.GenerateMockContentSettings();
private static readonly IWebRoutingSettings _settings = _configs.WebRouting();
private static Configs GetConfigs()
{
var configs = new ConfigsFactory().Create();
configs.Add(SettingsForTests.GetDefaultGlobalSettings);
configs.Add(SettingsForTests.GenerateMockContentSettings);
configs.Add(SettingsForTests.GetDefaultHostingSettings);
configs.Add(() => _globalSettings);
configs.Add(() => _contentSettings);
configs.Add(() => _hostingSettings);
return configs;
}
@@ -62,7 +62,9 @@ namespace Umbraco.Tests.Runtimes
var profiler = new LogProfiler(logger);
var profilingLogger = new ProfilingLogger(logger, profiler);
var appCaches = AppCaches.Disabled;
var databaseFactory = new UmbracoDatabaseFactory(logger, new Lazy<IMapperCollection>(() => factory.GetInstance<IMapperCollection>()), TestHelper.GetConfigs(), TestHelper.DbProviderFactoryCreator);
var globalSettings = TestHelper.GetConfigs().Global();
var connectionStrings = TestHelper.GetConfigs().ConnectionStrings();
var databaseFactory = new UmbracoDatabaseFactory(logger,globalSettings, connectionStrings, new Lazy<IMapperCollection>(() => factory.GetInstance<IMapperCollection>()), TestHelper.DbProviderFactoryCreator);
var typeFinder = new TypeFinder(logger, new DefaultUmbracoAssemblyProvider(GetType().Assembly));
var ioHelper = TestHelper.IOHelper;
var hostingEnvironment = Mock.Of<IHostingEnvironment>();
+8 -2
View File
@@ -244,12 +244,18 @@ namespace Umbraco.Tests.TestHelpers
// mappersBuilder.AddCore();
// var mappers = mappersBuilder.CreateCollection();
var mappers = Current.Factory.GetInstance<IMapperCollection>();
databaseFactory = new UmbracoDatabaseFactory(Constants.System.UmbracoConnectionName, logger, new Lazy<IMapperCollection>(() => mappers), TestHelper.GetConfigs(), TestHelper.DbProviderFactoryCreator);
databaseFactory = new UmbracoDatabaseFactory(
Constants.System.UmbracoConnectionName,
SettingsForTests.GetDefaultGlobalSettings(),
new ConnectionStrings(),
logger,
new Lazy<IMapperCollection>(() => mappers),
TestHelper.DbProviderFactoryCreator);
}
typeFinder = typeFinder ?? new TypeFinder(logger, new DefaultUmbracoAssemblyProvider(GetType().Assembly));
fileSystems = fileSystems ?? new FileSystems(Current.Factory, logger, TestHelper.IOHelper, SettingsForTests.GenerateMockGlobalSettings());
var coreDebug = Current.Configs.CoreDebug();
var coreDebug = TestHelper.CoreDebug;
var mediaFileSystem = Mock.Of<IMediaFileSystem>();
var scopeProvider = new ScopeProvider(databaseFactory, fileSystems, coreDebug, mediaFileSystem, logger, typeFinder, NoAppCache.Instance);
return scopeProvider;
+6 -1
View File
@@ -457,11 +457,16 @@ namespace Umbraco.Tests.Testing
.AddCoreMappers();
Composition.RegisterUnique<IEventMessagesFactory>(_ => new TransientEventMessagesFactory());
var globalSettings = TestHelper.GetConfigs().Global();
var connectionStrings = TestHelper.GetConfigs().ConnectionStrings();
Composition.RegisterUnique<IUmbracoDatabaseFactory>(f => new UmbracoDatabaseFactory(
Constants.System.UmbracoConnectionName,
globalSettings,
connectionStrings,
Logger,
new Lazy<IMapperCollection>(f.GetInstance<IMapperCollection>),
TestHelper.GetConfigs(),
TestHelper.DbProviderFactoryCreator));
Composition.RegisterUnique(f => f.TryGetInstance<IUmbracoDatabaseFactory>().SqlContext);
+5 -2
View File
@@ -22,10 +22,13 @@ namespace Umbraco.Web
var dbProviderFactoryCreator = new UmbracoDbProviderFactoryCreator(connectionStringConfig?.ProviderName);
var globalSettings = configs.Global();
var connectionStrings = configs.ConnectionStrings();
// Determine if we should use the sql main dom or the default
var appSettingMainDomLock = configs.Global().MainDomLock;
var appSettingMainDomLock = globalSettings.MainDomLock;
var mainDomLock = appSettingMainDomLock == "SqlMainDomLock"
? (IMainDomLock)new SqlMainDomLock(logger, configs, dbProviderFactoryCreator)
? (IMainDomLock)new SqlMainDomLock(logger, globalSettings, connectionStrings, dbProviderFactoryCreator)
: new MainDomSemaphoreLock(logger, hostingEnvironment);
var mainDom = new MainDom(logger, hostingEnvironment, mainDomLock);
+4 -4
View File
@@ -27,10 +27,10 @@ namespace Umbraco.Web
public class UmbracoDefaultOwinStartup
{
protected IUmbracoContextAccessor UmbracoContextAccessor => Current.UmbracoContextAccessor;
protected IGlobalSettings GlobalSettings => Current.Configs.Global();
protected IContentSettings ContentSettings => Current.Configs.Content();
protected ISecuritySettings SecuritySettings => Current.Configs.Security();
protected IUserPasswordConfiguration UserPasswordConfig => Current.Configs.UserPasswordConfiguration();
protected IGlobalSettings GlobalSettings => Current.Factory.GetInstance<IGlobalSettings>();
protected IContentSettings ContentSettings => Current.Factory.GetInstance<IContentSettings>();
protected ISecuritySettings SecuritySettings => Current.Factory.GetInstance<ISecuritySettings>();
protected IUserPasswordConfiguration UserPasswordConfig => Current.Factory.GetInstance<IUserPasswordConfiguration>();
protected IRuntimeState RuntimeState => Current.RuntimeState;
protected ServiceContext Services => Current.Services;
protected UmbracoMapper Mapper => Current.Mapper;