Netcore: Make composition root available as current in abstrations (#7500)
* Added all the essential parts of umbraco available on the Current from Abstractions. These are created when Current is initialized. * Moved some of the composers and components into Infrastructure - And removed unused Settings Files * Init current with null logger * Avoid multiple init of Current
This commit is contained in:
committed by
Elitsa Marinovska
parent
a9e6919420
commit
09b9c01f94
@@ -13,7 +13,7 @@ namespace Umbraco.Web.Actions
|
||||
: base(items)
|
||||
{ }
|
||||
|
||||
internal T GetAction<T>()
|
||||
public T GetAction<T>()
|
||||
where T : IAction
|
||||
{
|
||||
return this.OfType<T>().FirstOrDefault();
|
||||
|
||||
@@ -1,10 +1,57 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
|
||||
namespace Umbraco.Composing
|
||||
{
|
||||
public static class Current
|
||||
{
|
||||
private static bool _initialized;
|
||||
|
||||
public static ILogger Logger { get; set; } = new NullLogger();
|
||||
private static ILogger _logger = new NullLogger();
|
||||
private static Configs _configs;
|
||||
private static IIOHelper _ioHelper;
|
||||
private static IHostingEnvironment _hostingEnvironment;
|
||||
private static IBackOfficeInfo _backOfficeInfo;
|
||||
|
||||
public static ILogger Logger => EnsureInitialized(_logger);
|
||||
public static Configs Configs => EnsureInitialized(_configs);
|
||||
public static IIOHelper IOHelper => EnsureInitialized(_ioHelper);
|
||||
public static IHostingEnvironment HostingEnvironment => EnsureInitialized(_hostingEnvironment);
|
||||
public static IBackOfficeInfo BackOfficeInfo => EnsureInitialized(_backOfficeInfo);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static T EnsureInitialized<T>(T returnValue)
|
||||
where T : class
|
||||
{
|
||||
if (returnValue is null && !_initialized)
|
||||
throw new InvalidOperationException("Current cannot be used before initialize");
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
public static void Initialize(
|
||||
ILogger logger,
|
||||
Configs configs,
|
||||
IIOHelper ioHelper,
|
||||
IHostingEnvironment hostingEnvironment,
|
||||
IBackOfficeInfo backOfficeInfo)
|
||||
{
|
||||
if (_initialized)
|
||||
{
|
||||
throw new InvalidOperationException("Current cannot be initialized more than once");
|
||||
}
|
||||
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
_configs = configs ?? throw new ArgumentNullException(nameof(configs));
|
||||
_ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper));
|
||||
_hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment));
|
||||
_backOfficeInfo = backOfficeInfo ?? throw new ArgumentNullException(nameof(backOfficeInfo));
|
||||
|
||||
_initialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-8
@@ -9,6 +9,7 @@ using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Entities;
|
||||
using Umbraco.Core.Models.Identity;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Services.Implement;
|
||||
@@ -147,7 +148,7 @@ namespace Umbraco.Web.Compose
|
||||
/// </summary>
|
||||
public sealed class Notifier
|
||||
{
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
private readonly ICurrentUserAccessor _currentUserAccessor;
|
||||
private readonly IRuntimeState _runtimeState;
|
||||
private readonly INotificationService _notificationService;
|
||||
private readonly IUserService _userService;
|
||||
@@ -166,9 +167,9 @@ namespace Umbraco.Web.Compose
|
||||
/// <param name="globalSettings"></param>
|
||||
/// <param name="contentConfig"></param>
|
||||
/// <param name="logger"></param>
|
||||
public Notifier(IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState, INotificationService notificationService, IUserService userService, ILocalizedTextService textService, IGlobalSettings globalSettings, IContentSection contentConfig, ILogger logger)
|
||||
public Notifier(ICurrentUserAccessor currentUserAccessor, IRuntimeState runtimeState, INotificationService notificationService, IUserService userService, ILocalizedTextService textService, IGlobalSettings globalSettings, IContentSection contentConfig, ILogger logger)
|
||||
{
|
||||
_umbracoContextAccessor = umbracoContextAccessor;
|
||||
_currentUserAccessor = currentUserAccessor;
|
||||
_runtimeState = runtimeState;
|
||||
_notificationService = notificationService;
|
||||
_userService = userService;
|
||||
@@ -180,11 +181,7 @@ namespace Umbraco.Web.Compose
|
||||
|
||||
public void Notify(IAction action, params IContent[] entities)
|
||||
{
|
||||
IUser user = null;
|
||||
if (_umbracoContextAccessor.UmbracoContext != null)
|
||||
{
|
||||
user = _umbracoContextAccessor.UmbracoContext.Security.CurrentUser;
|
||||
}
|
||||
var user = _currentUserAccessor.TryGetCurrentUser();
|
||||
|
||||
//if there is no current user, then use the admin
|
||||
if (user == null)
|
||||
-1
@@ -3,7 +3,6 @@ using Umbraco.Core;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Services.Implement;
|
||||
using Current = Umbraco.Web.Composing.Current;
|
||||
|
||||
namespace Umbraco.Web.Compose
|
||||
{
|
||||
-54
@@ -1,54 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Umbraco.Web.Properties {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.2.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default {
|
||||
get {
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.ApplicationScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("http://regexlib.com/WebServices.asmx")]
|
||||
public string umbraco_com_regexlib_Webservices {
|
||||
get {
|
||||
return ((string)(this["umbraco_com_regexlib_Webservices"]));
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.ApplicationScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.WebServiceUrl)]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("http://update.umbraco.org/checkforupgrade.asmx")]
|
||||
public string umbraco_org_umbraco_update_CheckForUpgrade {
|
||||
get {
|
||||
return ((string)(this["umbraco_org_umbraco_update_CheckForUpgrade"]));
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.ApplicationScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("Something")]
|
||||
public string test {
|
||||
get {
|
||||
return ((string)(this["test"]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="Umbraco.Web.Properties" GeneratedClassName="Settings">
|
||||
<Profiles />
|
||||
<Settings>
|
||||
<Setting Name="umbraco_com_regexlib_Webservices" Type="System.String" Scope="Application">
|
||||
<Value Profile="(Default)">http://regexlib.com/WebServices.asmx</Value>
|
||||
</Setting>
|
||||
<Setting Name="umbraco_org_umbraco_update_CheckForUpgrade" Type="(Web Service URL)" Scope="Application">
|
||||
<Value Profile="(Default)">http://update.umbraco.org/checkforupgrade.asmx</Value>
|
||||
</Setting>
|
||||
<Setting Name="test" Type="System.String" Scope="Application">
|
||||
<Value Profile="(Default)">Something</Value>
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
||||
@@ -137,8 +137,6 @@
|
||||
<Compile Include="Compose\AuditEventsComponent.cs" />
|
||||
<Compile Include="Compose\AuditEventsComposer.cs" />
|
||||
<Compile Include="Compose\BackOfficeUserAuditEventsComposer.cs" />
|
||||
<Compile Include="Compose\NotificationsComposer.cs" />
|
||||
<Compile Include="Compose\PublicAccessComposer.cs" />
|
||||
<Compile Include="Composing\BuildManagerTypeFinder.cs" />
|
||||
<Compile Include="Composing\CompositionExtensions\Installer.cs" />
|
||||
<Compile Include="Composing\LightInject\LightInjectContainer.cs" />
|
||||
@@ -617,7 +615,6 @@
|
||||
<Compile Include="Security\UmbracoBackOfficeCookieAuthOptions.cs" />
|
||||
<Compile Include="Scheduling\TaskAndFactoryExtensions.cs" />
|
||||
<Compile Include="Migrations\PostMigrations\ClearCsrfCookies.cs" />
|
||||
<Compile Include="Compose\NotificationsComponent.cs" />
|
||||
<Compile Include="TagQuery.cs" />
|
||||
<Compile Include="Trees\CoreTreeAttribute.cs" />
|
||||
<Compile Include="Trees\DataTypeTreeController.cs" />
|
||||
@@ -722,7 +719,6 @@
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="JavaScript\ServerVariablesParser.cs" />
|
||||
<Compile Include="Compose\PublicAccessComponent.cs" />
|
||||
<Compile Include="CdfLogger.cs" />
|
||||
<Compile Include="Controllers\UmbLoginController.cs" />
|
||||
<Compile Include="UrlHelperExtensions.cs" />
|
||||
@@ -836,11 +832,6 @@
|
||||
<Compile Include="Macros\PublishedContentHashtableConverter.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="UmbracoApplication.cs" />
|
||||
<Compile Include="UmbracoContext.cs" />
|
||||
<Compile Include="UmbracoInjectedModule.cs" />
|
||||
@@ -899,10 +890,6 @@
|
||||
<None Include="Web References\org.umbraco.update\UpgradeResult1.datasource">
|
||||
<DependentUpon>Reference.map</DependentUpon>
|
||||
</None>
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<WebReferenceUrl Include="http://update.umbraco.org/checkforupgrade.asmx">
|
||||
|
||||
@@ -33,9 +33,6 @@ namespace Umbraco.Web
|
||||
|
||||
protected UmbracoApplicationBase()
|
||||
{
|
||||
|
||||
|
||||
|
||||
var configFactory = new ConfigsFactory();
|
||||
|
||||
var hostingSettings = configFactory.HostingSettings;
|
||||
@@ -50,7 +47,7 @@ namespace Umbraco.Web
|
||||
_logger = SerilogLogger.CreateWithDefaultConfiguration(_hostingEnvironment, new AspNetSessionIdResolver(), () => _factory?.GetInstance<IRequestCache>(), coreDebug, _ioHelper, new FrameworkMarchal());
|
||||
_backOfficeInfo = new AspNetBackOfficeInfo(_configs.Global(), _ioHelper, _configs.Settings(), _logger);
|
||||
|
||||
Umbraco.Composing.Current.Logger = _logger;
|
||||
Umbraco.Composing.Current.Initialize(_logger, _configs, _ioHelper, _hostingEnvironment, _backOfficeInfo);
|
||||
}
|
||||
|
||||
protected UmbracoApplicationBase(ILogger logger, Configs configs, IIOHelper ioHelper, IProfiler profiler, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo)
|
||||
@@ -61,6 +58,8 @@ namespace Umbraco.Web
|
||||
_profiler = profiler;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
_backOfficeInfo = backOfficeInfo;
|
||||
|
||||
Umbraco.Composing.Current.Initialize(_logger, _configs, _ioHelper, _hostingEnvironment, _backOfficeInfo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user