Removed unused private field and constructor variable for configuration global settings from UmbracoVersion.

Updated singleton created instances in CreateCompositionRoot to accept IOptions based parameters for configuration.
This commit is contained in:
Andy Butland
2020-09-03 11:36:57 +02:00
parent 8638419088
commit b87630250b
10 changed files with 30 additions and 41 deletions

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Options;
using Umbraco.Core.Configuration.Models;
using Umbraco.Core.Configuration.UmbracoSettings;
@@ -14,9 +15,9 @@ namespace Umbraco.Core.Composing
private readonly TypeFinderSettings _settings;
private IEnumerable<string> _assembliesAcceptingLoadExceptions;
public TypeFinderConfig(TypeFinderSettings settings)
public TypeFinderConfig(IOptions<TypeFinderSettings> settings)
{
_settings = settings;
_settings = settings.Value;
}
public IEnumerable<string> AssembliesAcceptingLoadExceptions

View File

@@ -1,7 +1,6 @@
using System;
using System.Reflection;
using Semver;
using Umbraco.Core.Configuration.Models;
namespace Umbraco.Core.Configuration
{
@@ -10,14 +9,6 @@ namespace Umbraco.Core.Configuration
/// </summary>
public class UmbracoVersion : IUmbracoVersion
{
private readonly GlobalSettings _globalSettings;
public UmbracoVersion(GlobalSettings globalSettings)
: this()
{
_globalSettings = globalSettings;
}
public UmbracoVersion()
{
var umbracoCoreAssembly = typeof(SemVersion).Assembly;

View File

@@ -128,7 +128,7 @@ namespace Umbraco.Tests.Common
return relativePath.Replace("~/", bin + "/");
}
public IUmbracoVersion GetUmbracoVersion() => new UmbracoVersion(new GlobalSettingsBuilder().Build());
public IUmbracoVersion GetUmbracoVersion() => new UmbracoVersion();
public IRegister GetRegister()
{

View File

@@ -20,6 +20,7 @@ using Umbraco.Tests.Common;
using Umbraco.Web.Common.AspNetCore;
using IHostingEnvironment = Umbraco.Core.Hosting.IHostingEnvironment;
using Umbraco.Tests.Common.Builders;
using Microsoft.Extensions.Options;
namespace Umbraco.Tests.Integration.Implementations
{
@@ -105,7 +106,7 @@ namespace Umbraco.Tests.Integration.Implementations
if (_backOfficeInfo == null)
{
var globalSettings = new GlobalSettingsBuilder().Build();
_backOfficeInfo = new AspNetCoreBackOfficeInfo(globalSettings);
_backOfficeInfo = new AspNetCoreBackOfficeInfo(Options.Create(globalSettings));
}
return _backOfficeInfo;

View File

@@ -1,5 +1,6 @@
using System;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Options;
using Moq;
using NUnit.Framework;
using Umbraco.Core;
@@ -48,7 +49,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Extensions
public void Is_Back_Office_Request(string input, string virtualPath, bool expected)
{
var hostingSettings = new HostingSettingsBuilder().WithApplicationVirtualPath(virtualPath).Build();
var hostingEnvironment = new AspNetCoreHostingEnvironment(hostingSettings, _hostEnvironment);
var hostingEnvironment = new AspNetCoreHostingEnvironment(Options.Create(hostingSettings), _hostEnvironment);
var source = new Uri(input);
Assert.AreEqual(expected, source.IsBackOfficeRequest(_globalSettings, hostingEnvironment));
@@ -67,7 +68,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Extensions
{
var source = new Uri(input);
var hostingSettings = new HostingSettingsBuilder().Build();
var hostingEnvironment = new AspNetCoreHostingEnvironment(hostingSettings, _hostEnvironment);
var hostingEnvironment = new AspNetCoreHostingEnvironment(Options.Create(hostingSettings), _hostEnvironment);
Assert.AreEqual(expected, source.IsInstallerRequest(hostingEnvironment));
}

View File

@@ -178,7 +178,7 @@ namespace Umbraco.Tests.Testing
IBackOfficeInfo backOfficeInfo = new AspNetBackOfficeInfo(ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings), IOHelper, logger, settings);
IIpResolver ipResolver = new AspNetIpResolver();
UmbracoVersion = new UmbracoVersion(globalSettings);
UmbracoVersion = new UmbracoVersion();
LocalizedTextService = new LocalizedTextService(new Dictionary<CultureInfo, Lazy<XDocument>>(), logger);

View File

@@ -7,13 +7,8 @@ namespace Umbraco.Web.Common.AspNetCore
public class AspNetCoreBackOfficeInfo : IBackOfficeInfo
{
public AspNetCoreBackOfficeInfo(IOptions<GlobalSettings> globalSettings)
: this(globalSettings.Value)
{
}
public AspNetCoreBackOfficeInfo(GlobalSettings globalSettings)
{
GetAbsoluteUrl = globalSettings.UmbracoPath;
GetAbsoluteUrl = globalSettings.Value.UmbracoPath;
}
public string GetAbsoluteUrl { get; } // TODO make absolute

View File

@@ -16,13 +16,8 @@ namespace Umbraco.Web.Common.AspNetCore
private string _localTempPath;
public AspNetCoreHostingEnvironment(IOptions<HostingSettings> hostingSettings, IWebHostEnvironment webHostEnvironment)
: this(hostingSettings.Value, webHostEnvironment)
{
}
public AspNetCoreHostingEnvironment(HostingSettings hostingSettings, IWebHostEnvironment webHostEnvironment)
{
_hostingSettings = hostingSettings ?? throw new ArgumentNullException(nameof(hostingSettings));
_hostingSettings = hostingSettings.Value ?? throw new ArgumentNullException(nameof(hostingSettings));
_webHostEnvironment = webHostEnvironment ?? throw new ArgumentNullException(nameof(webHostEnvironment));
SiteName = webHostEnvironment.ApplicationName;
@@ -30,7 +25,7 @@ namespace Umbraco.Web.Common.AspNetCore
ApplicationPhysicalPath = webHostEnvironment.ContentRootPath;
//TODO how to find this, This is a server thing, not application thing.
ApplicationVirtualPath = hostingSettings.ApplicationVirtualPath?.EnsureStartsWith('/')
ApplicationVirtualPath = _hostingSettings.ApplicationVirtualPath?.EnsureStartsWith('/')
?? "/";
IISVersion = new Version(0, 0); // TODO not necessary IIS

View File

@@ -126,6 +126,12 @@ namespace Umbraco.Extensions
services.Configure<UserPasswordConfigurationSettings>(configuration.GetSection(Constants.Configuration.ConfigSecurityPrefix + "UserPassword"));
services.Configure<WebRoutingSettings>(configuration.GetSection(Constants.Configuration.ConfigPrefix + "WebRouting"));
//services.Configure<TourSettings>(configuration.GetSection(Constants.Configuration.ConfigPrefix + "Tours"));
services.Configure<TourSettings>(settings =>
{
settings.EnableTours = false;
});
// TODO: remove this once no longer requred in Umbraco.Web.
var configsFactory = new AspNetCoreConfigsFactory(configuration);
var configs = configsFactory.Create();
@@ -224,10 +230,10 @@ namespace Umbraco.Extensions
// `RegisterEssentials`.
var serviceProvider = services.BuildServiceProvider();
var globalSettings = serviceProvider.GetService<IOptions<GlobalSettings>>().Value;
var connectionStrings = serviceProvider.GetService<IOptions<ConnectionStrings>>().Value;
var hostingSettings = serviceProvider.GetService<IOptions<HostingSettings>>().Value;
var typeFinderSettings = serviceProvider.GetService<IOptions<TypeFinderSettings>>().Value;
var globalSettings = serviceProvider.GetService<IOptions<GlobalSettings>>();
var connectionStrings = serviceProvider.GetService<IOptions<ConnectionStrings>>();
var hostingSettings = serviceProvider.GetService<IOptions<HostingSettings>>();
var typeFinderSettings = serviceProvider.GetService<IOptions<TypeFinderSettings>>();
var dbProviderFactoryCreator = serviceProvider.GetRequiredService<IDbProviderFactoryCreator>();
@@ -238,14 +244,14 @@ namespace Umbraco.Extensions
loggingConfiguration,
out var logger, out var ioHelper, out var hostingEnvironment, out var backOfficeInfo, out var profiler);
var umbracoVersion = new UmbracoVersion(globalSettings);
var umbracoVersion = new UmbracoVersion();
var typeFinder = CreateTypeFinder(logger, profiler, webHostEnvironment, entryAssembly, typeFinderSettings);
var configs = serviceProvider.GetService<Configs>();
var coreRuntime = GetCoreRuntime(
configs,
globalSettings,
connectionStrings,
globalSettings.Value,
connectionStrings.Value,
umbracoVersion,
ioHelper,
logger,
@@ -261,7 +267,7 @@ namespace Umbraco.Extensions
return services;
}
private static ITypeFinder CreateTypeFinder(Core.Logging.ILogger logger, IProfiler profiler, IWebHostEnvironment webHostEnvironment, Assembly entryAssembly, TypeFinderSettings typeFinderSettings)
private static ITypeFinder CreateTypeFinder(Core.Logging.ILogger logger, IProfiler profiler, IWebHostEnvironment webHostEnvironment, Assembly entryAssembly, IOptions<TypeFinderSettings> typeFinderSettings)
{
var runtimeHashPaths = new RuntimeHashPaths();
runtimeHashPaths.AddFolder(new DirectoryInfo(Path.Combine(webHostEnvironment.ContentRootPath, "bin")));
@@ -305,8 +311,8 @@ namespace Umbraco.Extensions
private static IServiceCollection CreateCompositionRoot(
IServiceCollection services,
GlobalSettings globalSettings,
HostingSettings hostingSettings,
IOptions<GlobalSettings> globalSettings,
IOptions<HostingSettings> hostingSettings,
IWebHostEnvironment webHostEnvironment,
ILoggingConfiguration loggingConfiguration,
out Core.Logging.ILogger logger,
@@ -318,7 +324,6 @@ namespace Umbraco.Extensions
if (globalSettings == null)
throw new InvalidOperationException($"Could not resolve type {typeof(GlobalSettings)} from the container, ensure {nameof(AddUmbracoConfiguration)} is called before calling {nameof(AddUmbracoCore)}");
hostingEnvironment = new AspNetCoreHostingEnvironment(hostingSettings, webHostEnvironment);
ioHelper = new IOHelper(hostingEnvironment);
logger = AddLogger(services, hostingEnvironment, loggingConfiguration);

View File

@@ -160,7 +160,7 @@ namespace Umbraco.Web
var globalSettings = Umbraco.Composing.Current.Configs.Global();
var umbracoVersion = new UmbracoVersion(ConfigModelConversionsFromLegacy.ConvertGlobalSettings(globalSettings));
var umbracoVersion = new UmbracoVersion();
// create the register for the application, and boot
// the boot manager is responsible for registrations