Updated classes to use IOptionsMonitor or IOptionsSnapshot instead of IOptions
This commit is contained in:
@@ -35,11 +35,12 @@ namespace Umbraco.Cms.Core.Security
|
||||
IdentityErrorDescriber errors,
|
||||
IServiceProvider services,
|
||||
ILogger<UserManager<TUser>> logger,
|
||||
IOptions<TPasswordConfig> passwordConfiguration)
|
||||
IOptionsMonitor<TPasswordConfig> passwordConfiguration)
|
||||
: base(store, optionsAccessor, passwordHasher, userValidators, passwordValidators, new NoopLookupNormalizer(), errors, services, logger)
|
||||
{
|
||||
IpResolver = ipResolver ?? throw new ArgumentNullException(nameof(ipResolver));
|
||||
PasswordConfiguration = passwordConfiguration.Value ?? throw new ArgumentNullException(nameof(passwordConfiguration));
|
||||
PasswordConfiguration = passwordConfiguration.CurrentValue ?? throw new ArgumentNullException(nameof(passwordConfiguration));
|
||||
passwordConfiguration.OnChange(x => PasswordConfiguration = x);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -60,7 +61,7 @@ namespace Umbraco.Cms.Core.Security
|
||||
/// <summary>
|
||||
/// Gets the password configuration
|
||||
/// </summary>
|
||||
public IPasswordConfiguration PasswordConfiguration { get; }
|
||||
public IPasswordConfiguration PasswordConfiguration { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the IP resolver
|
||||
@@ -96,7 +97,7 @@ namespace Umbraco.Cms.Core.Security
|
||||
string password = _passwordGenerator.GeneratePassword();
|
||||
return password;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Used to validate the password without an identity user
|
||||
/// Validation code is based on the default ValidatePasswordAsync code
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Security
|
||||
private Mock<IPasswordHasher<MemberIdentityUser>> _mockPasswordHasher;
|
||||
private Mock<IMemberService> _mockMemberService;
|
||||
private Mock<IServiceProvider> _mockServiceProviders;
|
||||
private Mock<IOptions<MemberPasswordConfigurationSettings>> _mockPasswordConfiguration;
|
||||
private Mock<IOptionsMonitor<MemberPasswordConfigurationSettings>> _mockPasswordConfiguration;
|
||||
|
||||
public MemberManager CreateSut()
|
||||
{
|
||||
@@ -65,8 +65,8 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Security
|
||||
userValidators.Add(validator.Object);
|
||||
|
||||
_mockServiceProviders = new Mock<IServiceProvider>();
|
||||
_mockPasswordConfiguration = new Mock<IOptions<MemberPasswordConfigurationSettings>>();
|
||||
_mockPasswordConfiguration.Setup(x => x.Value).Returns(() =>
|
||||
_mockPasswordConfiguration = new Mock<IOptionsMonitor<MemberPasswordConfigurationSettings>>();
|
||||
_mockPasswordConfiguration.Setup(x => x.CurrentValue).Returns(() =>
|
||||
new MemberPasswordConfigurationSettings()
|
||||
{
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ using NUnit.Framework;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Configuration.Models;
|
||||
using Umbraco.Cms.Core.Hosting;
|
||||
using Umbraco.Cms.Tests.Common;
|
||||
using Umbraco.Cms.Web.Common.Routing;
|
||||
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.Common.Routing
|
||||
@@ -91,7 +92,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.Common.Routing
|
||||
var endpointDataSource = new DefaultEndpointDataSource(endpoint1, endpoint2);
|
||||
|
||||
var routableDocFilter = new RoutableDocumentFilter(
|
||||
Options.Create(globalSettings),
|
||||
new TestOptionsSnapshot<GlobalSettings>(globalSettings),
|
||||
Options.Create(routingSettings),
|
||||
GetHostingEnvironment(),
|
||||
endpointDataSource);
|
||||
@@ -120,7 +121,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.Common.Routing
|
||||
var endpointDataSource = new DefaultEndpointDataSource(endpoint1);
|
||||
|
||||
var routableDocFilter = new RoutableDocumentFilter(
|
||||
Options.Create(globalSettings),
|
||||
new TestOptionsSnapshot<GlobalSettings>(globalSettings),
|
||||
Options.Create(routingSettings),
|
||||
GetHostingEnvironment(),
|
||||
endpointDataSource);
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.Website.Controllers
|
||||
var mockUmbracoContext = new Mock<IUmbracoContext>();
|
||||
mockUmbracoContext.Setup(x => x.Content.HasContent()).Returns(true);
|
||||
var mockIOHelper = new Mock<IIOHelper>();
|
||||
var controller = new RenderNoContentController(new TestUmbracoContextAccessor(mockUmbracoContext.Object), mockIOHelper.Object, Options.Create(new GlobalSettings()));
|
||||
var controller = new RenderNoContentController(new TestUmbracoContextAccessor(mockUmbracoContext.Object), mockIOHelper.Object, new TestOptionsSnapshot<GlobalSettings>(new GlobalSettings()));
|
||||
|
||||
var result = controller.Index() as RedirectResult;
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.Website.Controllers
|
||||
var mockIOHelper = new Mock<IIOHelper>();
|
||||
mockIOHelper.Setup(x => x.ResolveUrl(It.Is<string>(y => y == UmbracoPathSetting))).Returns(UmbracoPath);
|
||||
|
||||
IOptions<GlobalSettings> globalSettings = Options.Create(new GlobalSettings()
|
||||
var globalSettings = new TestOptionsSnapshot<GlobalSettings>(new GlobalSettings()
|
||||
{
|
||||
UmbracoPath = UmbracoPathSetting,
|
||||
NoNodesViewPath = ViewPath,
|
||||
|
||||
@@ -15,18 +15,20 @@ namespace Umbraco.Cms.Web.BackOffice.Services
|
||||
{
|
||||
public class IconService : IIconService
|
||||
{
|
||||
private readonly IOptions<GlobalSettings> _globalSettings;
|
||||
private GlobalSettings _globalSettings;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
private readonly IAppPolicyCache _cache;
|
||||
|
||||
public IconService(
|
||||
IOptions<GlobalSettings> globalSettings,
|
||||
IOptionsMonitor<GlobalSettings> globalSettings,
|
||||
IHostingEnvironment hostingEnvironment,
|
||||
AppCaches appCaches)
|
||||
{
|
||||
_globalSettings = globalSettings;
|
||||
_globalSettings = globalSettings.CurrentValue;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
_cache = appCaches.RuntimeCache;
|
||||
|
||||
globalSettings.OnChange(x => _globalSettings = x);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -114,7 +116,7 @@ namespace Umbraco.Cms.Web.BackOffice.Services
|
||||
}
|
||||
|
||||
// add icons from IconsPath if not already added from plugins
|
||||
var coreIconsDirectory = new DirectoryInfo(_hostingEnvironment.MapPathWebRoot($"{_globalSettings.Value.IconsPath}/"));
|
||||
var coreIconsDirectory = new DirectoryInfo(_hostingEnvironment.MapPathWebRoot($"{_globalSettings.IconsPath}/"));
|
||||
var coreIcons = coreIconsDirectory.GetFiles("*.svg");
|
||||
|
||||
icons.UnionWith(coreIcons);
|
||||
|
||||
@@ -25,12 +25,12 @@ namespace Umbraco.Cms.Web.Common.Filters
|
||||
private readonly string _format = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
private readonly ArrayPool<char> _arrayPool;
|
||||
private readonly IOptions<MvcOptions> _options;
|
||||
private readonly MvcOptions _options;
|
||||
|
||||
public JsonDateTimeFormatFilter(ArrayPool<char> arrayPool, IOptions<MvcOptions> options)
|
||||
public JsonDateTimeFormatFilter(ArrayPool<char> arrayPool, IOptionsSnapshot<MvcOptions> options)
|
||||
{
|
||||
_arrayPool = arrayPool;
|
||||
_options = options;
|
||||
_options = options.Value;
|
||||
}
|
||||
|
||||
public void OnResultExecuted(ResultExecutedContext context)
|
||||
@@ -47,9 +47,8 @@ namespace Umbraco.Cms.Web.Common.Filters
|
||||
{
|
||||
DateTimeFormat = _format
|
||||
});
|
||||
|
||||
objectResult.Formatters.Clear();
|
||||
objectResult.Formatters.Add(new AngularJsonMediaTypeFormatter(serializerSettings, _arrayPool, _options.Value));
|
||||
objectResult.Formatters.Add(new AngularJsonMediaTypeFormatter(serializerSettings, _arrayPool, _options));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace Umbraco.Cms.Web.Common.Filters
|
||||
private readonly ExceptionFilterSettings _exceptionFilterSettings;
|
||||
private readonly IPublishedModelFactory _publishedModelFactory;
|
||||
|
||||
public ModelBindingExceptionFilter(IOptions<ExceptionFilterSettings> exceptionFilterSettings, IPublishedModelFactory publishedModelFactory)
|
||||
public ModelBindingExceptionFilter(IOptionsSnapshot<ExceptionFilterSettings> exceptionFilterSettings, IPublishedModelFactory publishedModelFactory)
|
||||
{
|
||||
_exceptionFilterSettings = exceptionFilterSettings.Value;
|
||||
_publishedModelFactory = publishedModelFactory ?? throw new ArgumentNullException(nameof(publishedModelFactory));
|
||||
|
||||
@@ -18,14 +18,13 @@ namespace Umbraco.Cms.Web.Common.Filters
|
||||
|
||||
private class OutgoingNoHyphenGuidFormatFilter : IResultFilter
|
||||
{
|
||||
private readonly IOptions<MvcNewtonsoftJsonOptions> _mvcNewtonsoftJsonOptions;
|
||||
private readonly ArrayPool<char> _arrayPool;
|
||||
private readonly IOptions<MvcOptions> _options;
|
||||
private readonly MvcOptions _options;
|
||||
|
||||
public OutgoingNoHyphenGuidFormatFilter(ArrayPool<char> arrayPool, IOptions<MvcOptions> options)
|
||||
public OutgoingNoHyphenGuidFormatFilter(ArrayPool<char> arrayPool, IOptionsSnapshot<MvcOptions> options)
|
||||
{
|
||||
_arrayPool = arrayPool;
|
||||
_options = options;
|
||||
_options = options.Value;
|
||||
}
|
||||
public void OnResultExecuted(ResultExecutedContext context)
|
||||
{
|
||||
@@ -39,7 +38,7 @@ namespace Umbraco.Cms.Web.Common.Filters
|
||||
serializerSettings.Converters.Add(new GuidNoHyphenConverter());
|
||||
|
||||
objectResult.Formatters.Clear();
|
||||
objectResult.Formatters.Add(new AngularJsonMediaTypeFormatter(serializerSettings, _arrayPool, _options.Value));
|
||||
objectResult.Formatters.Add(new AngularJsonMediaTypeFormatter(serializerSettings, _arrayPool, _options));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,18 +11,22 @@ namespace Umbraco.Cms.Web.Common.Localization
|
||||
/// </summary>
|
||||
public class UmbracoRequestLocalizationOptions : IConfigureOptions<RequestLocalizationOptions>
|
||||
{
|
||||
private readonly IOptions<GlobalSettings> _globalSettings;
|
||||
private GlobalSettings _globalSettings;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UmbracoRequestLocalizationOptions"/> class.
|
||||
/// </summary>
|
||||
public UmbracoRequestLocalizationOptions(IOptions<GlobalSettings> globalSettings) => _globalSettings = globalSettings;
|
||||
public UmbracoRequestLocalizationOptions(IOptionsMonitor<GlobalSettings> globalSettings)
|
||||
{
|
||||
_globalSettings = globalSettings.CurrentValue;
|
||||
globalSettings.OnChange(x => _globalSettings = x);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Configure(RequestLocalizationOptions options)
|
||||
{
|
||||
// set the default culture to what is in config
|
||||
options.DefaultRequestCulture = new RequestCulture(_globalSettings.Value.DefaultUILanguage);
|
||||
options.DefaultRequestCulture = new RequestCulture(_globalSettings.DefaultUILanguage);
|
||||
|
||||
// add a custom provider
|
||||
if (options.RequestCultureProviders == null)
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Umbraco.Cms.Web.Common.Macros
|
||||
private readonly IProfilingLogger _profilingLogger;
|
||||
private readonly ILogger<MacroRenderer> _logger;
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
private readonly ContentSettings _contentSettings;
|
||||
private ContentSettings _contentSettings;
|
||||
private readonly ILocalizedTextService _textService;
|
||||
private readonly AppCaches _appCaches;
|
||||
private readonly IMacroService _macroService;
|
||||
@@ -43,7 +43,7 @@ namespace Umbraco.Cms.Web.Common.Macros
|
||||
IProfilingLogger profilingLogger,
|
||||
ILogger<MacroRenderer> logger,
|
||||
IUmbracoContextAccessor umbracoContextAccessor,
|
||||
IOptions<ContentSettings> contentSettings,
|
||||
IOptionsMonitor<ContentSettings> contentSettings,
|
||||
ILocalizedTextService textService,
|
||||
AppCaches appCaches,
|
||||
IMacroService macroService,
|
||||
@@ -57,7 +57,7 @@ namespace Umbraco.Cms.Web.Common.Macros
|
||||
_profilingLogger = profilingLogger ?? throw new ArgumentNullException(nameof(profilingLogger));
|
||||
_logger = logger;
|
||||
_umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor));
|
||||
_contentSettings = contentSettings.Value ?? throw new ArgumentNullException(nameof(contentSettings));
|
||||
_contentSettings = contentSettings.CurrentValue ?? throw new ArgumentNullException(nameof(contentSettings));
|
||||
_textService = textService;
|
||||
_appCaches = appCaches ?? throw new ArgumentNullException(nameof(appCaches));
|
||||
_macroService = macroService ?? throw new ArgumentNullException(nameof(macroService));
|
||||
@@ -67,6 +67,8 @@ namespace Umbraco.Cms.Web.Common.Macros
|
||||
_requestAccessor = requestAccessor;
|
||||
_partialViewMacroEngine = partialViewMacroEngine;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
|
||||
contentSettings.OnChange(x => _contentSettings = x);
|
||||
}
|
||||
|
||||
#region MacroContent cache
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace Umbraco.Cms.Web.Common.Middleware
|
||||
private readonly IRuntimeState _runtimeState;
|
||||
private readonly IVariationContextAccessor _variationContextAccessor;
|
||||
private readonly IDefaultCultureAccessor _defaultCultureAccessor;
|
||||
private readonly SmidgeOptions _smidgeOptions;
|
||||
private SmidgeOptions _smidgeOptions;
|
||||
private readonly WebProfiler _profiler;
|
||||
|
||||
private static bool s_cacheInitialized;
|
||||
@@ -79,7 +79,7 @@ namespace Umbraco.Cms.Web.Common.Middleware
|
||||
IHostingEnvironment hostingEnvironment,
|
||||
UmbracoRequestPaths umbracoRequestPaths,
|
||||
BackOfficeWebAssets backOfficeWebAssets,
|
||||
IOptions<SmidgeOptions> smidgeOptions,
|
||||
IOptionsMonitor<SmidgeOptions> smidgeOptions,
|
||||
IRuntimeState runtimeState,
|
||||
IVariationContextAccessor variationContextAccessor,
|
||||
IDefaultCultureAccessor defaultCultureAccessor)
|
||||
@@ -95,8 +95,10 @@ namespace Umbraco.Cms.Web.Common.Middleware
|
||||
_runtimeState = runtimeState;
|
||||
_variationContextAccessor = variationContextAccessor;
|
||||
_defaultCultureAccessor = defaultCultureAccessor;
|
||||
_smidgeOptions = smidgeOptions.Value;
|
||||
_smidgeOptions = smidgeOptions.CurrentValue;
|
||||
_profiler = profiler as WebProfiler; // Ignore if not a WebProfiler
|
||||
|
||||
smidgeOptions.OnChange(x => _smidgeOptions = x);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Umbraco.Cms.Web.Common.Security
|
||||
IServiceProvider services,
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
ILogger<UserManager<BackOfficeIdentityUser>> logger,
|
||||
IOptions<UserPasswordConfigurationSettings> passwordConfiguration,
|
||||
IOptionsMonitor<UserPasswordConfigurationSettings> passwordConfiguration,
|
||||
IEventAggregator eventAggregator,
|
||||
IBackOfficeUserPasswordChecker backOfficeUserPasswordChecker)
|
||||
: base(ipResolver, store, optionsAccessor, passwordHasher, userValidators, passwordValidators, errors, services, logger, passwordConfiguration)
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Umbraco.Cms.Web.Common.Security
|
||||
IdentityErrorDescriber errors,
|
||||
IServiceProvider services,
|
||||
ILogger<UserManager<MemberIdentityUser>> logger,
|
||||
IOptions<MemberPasswordConfigurationSettings> passwordConfiguration,
|
||||
IOptionsMonitor<MemberPasswordConfigurationSettings> passwordConfiguration,
|
||||
IPublicAccessService publicAccessService,
|
||||
IHttpContextAccessor httpContextAccessor)
|
||||
: base(ipResolver, store, optionsAccessor, passwordHasher, userValidators, passwordValidators, errors,
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Umbraco.Cms.Web.Common.Templates
|
||||
private readonly IPublishedRouter _publishedRouter;
|
||||
private readonly IFileService _fileService;
|
||||
private readonly ILocalizationService _languageService;
|
||||
private readonly WebRoutingSettings _webRoutingSettings;
|
||||
private WebRoutingSettings _webRoutingSettings;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly ICompositeViewEngine _viewEngine;
|
||||
private readonly IModelMetadataProvider _modelMetadataProvider;
|
||||
@@ -46,7 +46,7 @@ namespace Umbraco.Cms.Web.Common.Templates
|
||||
IPublishedRouter publishedRouter,
|
||||
IFileService fileService,
|
||||
ILocalizationService textService,
|
||||
IOptions<WebRoutingSettings> webRoutingSettings,
|
||||
IOptionsMonitor<WebRoutingSettings> webRoutingSettings,
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
ICompositeViewEngine viewEngine,
|
||||
IModelMetadataProvider modelMetadataProvider,
|
||||
@@ -56,11 +56,13 @@ namespace Umbraco.Cms.Web.Common.Templates
|
||||
_publishedRouter = publishedRouter ?? throw new ArgumentNullException(nameof(publishedRouter));
|
||||
_fileService = fileService ?? throw new ArgumentNullException(nameof(fileService));
|
||||
_languageService = textService ?? throw new ArgumentNullException(nameof(textService));
|
||||
_webRoutingSettings = webRoutingSettings.Value ?? throw new ArgumentNullException(nameof(webRoutingSettings));
|
||||
_webRoutingSettings = webRoutingSettings.CurrentValue ?? throw new ArgumentNullException(nameof(webRoutingSettings));
|
||||
_httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor));
|
||||
_viewEngine = viewEngine ?? throw new ArgumentNullException(nameof(viewEngine));
|
||||
_modelMetadataProvider = modelMetadataProvider;
|
||||
_tempDataDictionaryFactory = tempDataDictionaryFactory;
|
||||
|
||||
webRoutingSettings.OnChange(x => _webRoutingSettings = x);
|
||||
}
|
||||
|
||||
public async Task RenderAsync(int pageId, int? altTemplateId, StringWriter writer)
|
||||
|
||||
@@ -13,13 +13,13 @@ namespace Umbraco.Cms.Web.Website.Controllers
|
||||
{
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly IOptions<GlobalSettings> _globalSettings;
|
||||
private readonly GlobalSettings _globalSettings;
|
||||
|
||||
public RenderNoContentController(IUmbracoContextAccessor umbracoContextAccessor, IIOHelper ioHelper, IOptions<GlobalSettings> globalSettings)
|
||||
public RenderNoContentController(IUmbracoContextAccessor umbracoContextAccessor, IIOHelper ioHelper, IOptionsSnapshot<GlobalSettings> globalSettings)
|
||||
{
|
||||
_umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor));
|
||||
_ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper));
|
||||
_globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings));
|
||||
_globalSettings = globalSettings.Value ?? throw new ArgumentNullException(nameof(globalSettings));
|
||||
}
|
||||
|
||||
public ActionResult Index()
|
||||
@@ -34,10 +34,10 @@ namespace Umbraco.Cms.Web.Website.Controllers
|
||||
|
||||
var model = new NoNodesViewModel
|
||||
{
|
||||
UmbracoPath = _ioHelper.ResolveUrl(_globalSettings.Value.UmbracoPath),
|
||||
UmbracoPath = _ioHelper.ResolveUrl(_globalSettings.UmbracoPath),
|
||||
};
|
||||
|
||||
return View(_globalSettings.Value.NoNodesViewPath, model);
|
||||
return View(_globalSettings.NoNodesViewPath, model);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user