Few more NRT tweaks (#12323)

* Amended GetAll() on IDataTypeService to return an empty collection rather than null.

* Added a ClearSessionValue method to ISessionManager (given you can no longer set a value to null).

* Allow for null values in a StatefulNotification.

* Removed obsoletion of synchronous messages on TreeControllerBase.

* Fixed further CS8620 warnings in core project.

* Further fix to nullable warning.

* Aligned nullablility of retreiving tree nodes and menus, synchronously or asynchronously (such that we no longer can get null values, always empty collection objects).
This commit is contained in:
Andy Butland
2022-05-01 08:18:09 +02:00
committed by GitHub
parent d47ae6868b
commit 96d33201aa
31 changed files with 102 additions and 77 deletions

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Cms.Core.Collections;

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Cms.Core.PropertyEditors;
@@ -84,7 +84,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
if (_publishedDataTypes == null)
{
var dataTypes = _dataTypeService.GetAll();
_publishedDataTypes = dataTypes?.ToDictionary(x => x.Id, CreatePublishedDataType);
_publishedDataTypes = dataTypes.ToDictionary(x => x.Id, CreatePublishedDataType);
}
publishedDataTypes = _publishedDataTypes;
@@ -104,7 +104,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
if (_publishedDataTypes == null)
{
var dataTypes = _dataTypeService.GetAll();
_publishedDataTypes = dataTypes?.ToDictionary(x => x.Id, CreatePublishedDataType);
_publishedDataTypes = dataTypes.ToDictionary(x => x.Id, CreatePublishedDataType);
}
else
{
@@ -112,11 +112,8 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
_publishedDataTypes.Remove(id);
var dataTypes = _dataTypeService.GetAll(ids);
if (dataTypes is not null)
{
foreach (var dataType in dataTypes)
_publishedDataTypes[dataType.Id] = CreatePublishedDataType(dataType);
}
foreach (var dataType in dataTypes)
_publishedDataTypes[dataType.Id] = CreatePublishedDataType(dataType);
}
}
}

View File

@@ -4,6 +4,6 @@ namespace Umbraco.Cms.Core.Notifications
{
public interface IStatefulNotification : INotification
{
IDictionary<string, object> State { get; set; }
IDictionary<string, object?> State { get; set; }
}
}

View File

@@ -4,7 +4,7 @@ namespace Umbraco.Cms.Core.Notifications
{
public static class NotificationExtensions
{
public static T WithState<T>(this T notification, IDictionary<string, object>? state) where T : IStatefulNotification
public static T WithState<T>(this T notification, IDictionary<string, object?>? state) where T : IStatefulNotification
{
notification.State = state!;
return notification;

View File

@@ -6,15 +6,15 @@ namespace Umbraco.Cms.Core.Notifications
{
public abstract class StatefulNotification : IStatefulNotification
{
private IDictionary<string, object>? _state;
private IDictionary<string, object?>? _state;
/// <summary>
/// This can be used by event subscribers to store state in the notification so they easily deal with custom state data between
/// a starting ("ing") and an ending ("ed") notification
/// </summary>
public IDictionary<string, object> State
public IDictionary<string, object?> State
{
get => _state ??= new Dictionary<string, object>();
get => _state ??= new Dictionary<string, object?>();
set => _state = value;
}
}

View File

@@ -1377,7 +1377,7 @@ namespace Umbraco.Cms.Core.Services
/// </remarks>
private PublishResult CommitDocumentChangesInternal(ICoreScope scope, IContent content,
EventMessages eventMessages, IReadOnlyCollection<ILanguage> allLangs,
IDictionary<string, object>? notificationState,
IDictionary<string, object?>? notificationState,
int userId = Constants.Security.SuperUserId,
bool branchOne = false, bool branchRoot = false)
{
@@ -3036,7 +3036,7 @@ namespace Umbraco.Cms.Core.Services
private PublishResult StrategyCanPublish(ICoreScope scope, IContent content, bool checkPath,
IReadOnlyList<string>? culturesPublishing,
IReadOnlyCollection<string>? culturesUnpublishing, EventMessages evtMsgs,
IReadOnlyCollection<ILanguage> allLangs, IDictionary<string, object>? notificationState)
IReadOnlyCollection<ILanguage> allLangs, IDictionary<string, object?>? notificationState)
{
// raise Publishing notification
if (scope.Notifications.PublishCancelable(

View File

@@ -364,15 +364,11 @@ namespace Umbraco.Cms.Core.Services.Implement
/// </summary>
/// <param name="ids">Optional array of Ids</param>
/// <returns>An enumerable list of <see cref="IDataType"/> objects</returns>
public IEnumerable<IDataType>? GetAll(params int[] ids)
public IEnumerable<IDataType> GetAll(params int[] ids)
{
using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true))
{
var dataTypes = _dataTypeRepository.GetMany(ids);
if (dataTypes is null)
{
return null;
}
ConvertMissingEditorsOfDataTypesToLabels(dataTypes);
return dataTypes;

View File

@@ -53,7 +53,7 @@ namespace Umbraco.Cms.Core.Services
/// </summary>
/// <param name="ids">Optional array of Ids</param>
/// <returns>An enumerable list of <see cref="IDataType"/> objects</returns>
IEnumerable<IDataType>? GetAll(params int[] ids);
IEnumerable<IDataType> GetAll(params int[] ids);
/// <summary>
/// Saves an <see cref="IDataType"/>

View File

@@ -852,7 +852,7 @@ namespace Umbraco.Cms.Core.Services
}
}
private void DeleteLocked(ICoreScope scope, IMember member, EventMessages evtMsgs, IDictionary<string, object>? notificationState = null)
private void DeleteLocked(ICoreScope scope, IMember member, EventMessages evtMsgs, IDictionary<string, object?>? notificationState = null)
{
// a member has no descendants
_memberRepository.Delete(member);

View File

@@ -2,7 +2,10 @@ namespace Umbraco.Cms.Core.Web
{
public interface ISessionManager
{
string? GetSessionValue(string sessionName);
void SetSessionValue(string sessionName, string value);
string? GetSessionValue(string key);
void SetSessionValue(string key, string value);
void ClearSessionValue(string key);
}
}

View File

@@ -90,7 +90,7 @@ namespace Umbraco.Cms.Core.Routing
notification.State[NotificationStateKey] = new OldRoutesDictionary();
}
return (OldRoutesDictionary)notification.State[NotificationStateKey];
return (OldRoutesDictionary?)notification.State[NotificationStateKey] ?? new OldRoutesDictionary();
}
private void StoreOldRoute(IContent entity, OldRoutesDictionary oldRoutes)

View File

@@ -424,8 +424,8 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
[Authorize(Policy = AuthorizationPolicies.SectionAccessForDataTypeReading)]
public IEnumerable<DataTypeBasic>? GetAll()
{
return _dataTypeService?
.GetAll()?
return _dataTypeService
.GetAll()
.Select(_umbracoMapper.Map<IDataType, DataTypeBasic>).WhereNotNull().Where(x => x.IsSystemDataType == false);
}
@@ -439,8 +439,8 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
[Authorize(Policy = AuthorizationPolicies.SectionAccessForDataTypeReading)]
public IDictionary<string, IEnumerable<DataTypeBasic>>? GetGroupedDataTypes()
{
var dataTypes = _dataTypeService?
.GetAll()?
var dataTypes = _dataTypeService
.GetAll()
.Select(_umbracoMapper.Map<IDataType, DataTypeBasic>)
.ToArray();

View File

@@ -73,7 +73,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
return root;
}
protected override ActionResult<TreeNodeCollection?> GetTreeNodes(string id, FormCollection queryStrings)
protected override ActionResult<TreeNodeCollection> GetTreeNodes(string id, FormCollection queryStrings)
{
var nodes = new TreeNodeCollection();

View File

@@ -187,7 +187,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
/// </summary>
protected abstract int[] UserStartNodes { get; }
protected virtual ActionResult<TreeNodeCollection?> PerformGetTreeNodes(string id, FormCollection queryStrings)
protected virtual ActionResult<TreeNodeCollection> PerformGetTreeNodes(string id, FormCollection queryStrings)
{
var nodes = new TreeNodeCollection();
@@ -345,7 +345,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
/// <remarks>
/// This method is overwritten strictly to render the recycle bin, it should serve no other purpose
/// </remarks>
protected sealed override ActionResult<TreeNodeCollection?> GetTreeNodes(string id, FormCollection queryStrings)
protected sealed override ActionResult<TreeNodeCollection> GetTreeNodes(string id, FormCollection queryStrings)
{
//check if we're rendering the root
if (id == Constants.System.RootString && UserStartNodes.Contains(Constants.System.Root))
@@ -384,7 +384,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
queryStrings.GetRequiredValue<string>("application") + TreeAlias.EnsureStartsWith('/') + "/recyclebin"));
}
return nodes;
return nodes ?? new TreeNodeCollection();
}
return GetTreeNodesInternal(id, queryStrings);
@@ -435,7 +435,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
/// <remarks>
/// Currently this just checks if it is a container type, if it is we cannot render children. In the future this might check for other things.
/// </remarks>
private ActionResult<TreeNodeCollection?> GetTreeNodesInternal(string id, FormCollection queryStrings)
private ActionResult<TreeNodeCollection> GetTreeNodesInternal(string id, FormCollection queryStrings)
{
var current = GetEntityFromId(id);

View File

@@ -58,7 +58,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
return root;
}
protected override ActionResult<TreeNodeCollection?> GetTreeNodes(string id, FormCollection queryStrings)
protected override ActionResult<TreeNodeCollection> GetTreeNodes(string id, FormCollection queryStrings)
{
if (!int.TryParse(id, NumberStyles.Integer, CultureInfo.InvariantCulture, out var intId))
{

View File

@@ -41,7 +41,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
_dataTypeService = dataTypeService;
}
protected override ActionResult<TreeNodeCollection?> GetTreeNodes(string id, FormCollection queryStrings)
protected override ActionResult<TreeNodeCollection> GetTreeNodes(string id, FormCollection queryStrings)
{
if (!int.TryParse(id, NumberStyles.Integer, CultureInfo.InvariantCulture, out var intId))
{
@@ -71,7 +71,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
var systemListViewDataTypeIds = GetNonDeletableSystemListViewDataTypeIds();
var children = _entityService.GetChildren(intId, UmbracoObjectTypes.DataType).ToArray();
var dataTypes = Enumerable.ToDictionary(_dataTypeService.GetAll(children.Select(c => c.Id).ToArray()) ?? Enumerable.Empty<IDataType>(), dt => dt.Id);
var dataTypes = Enumerable.ToDictionary(_dataTypeService.GetAll(children.Select(c => c.Id).ToArray()), dt => dt.Id);
nodes.AddRange(
children

View File

@@ -71,7 +71,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
/// We are allowing an arbitrary number of query strings to be passed in so that developers are able to persist custom data from the front-end
/// to the back end to be used in the query for model data.
/// </remarks>
protected override ActionResult<TreeNodeCollection?> GetTreeNodes(string id, FormCollection queryStrings)
protected override ActionResult<TreeNodeCollection> GetTreeNodes(string id, FormCollection queryStrings)
{
if (!int.TryParse(id, NumberStyles.Integer, CultureInfo.InvariantCulture, out var intId))
{

View File

@@ -49,7 +49,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
treeNode.AdditionalData["jsClickCallback"] = "javascript:void(0);";
}
protected override ActionResult<TreeNodeCollection?> GetTreeNodes(string id, FormCollection queryStrings)
protected override ActionResult<TreeNodeCollection> GetTreeNodes(string id, FormCollection queryStrings)
{
var path = string.IsNullOrEmpty(id) == false && id != Constants.System.RootString
? WebUtility.UrlDecode(id).TrimStart("/")

View File

@@ -17,24 +17,28 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
[CoreTree]
public class LanguageTreeController : TreeController
{
private readonly IMenuItemCollectionFactory _menuItemCollectionFactory;
public LanguageTreeController(
ILocalizedTextService textService,
UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection,
IEventAggregator eventAggregator)
IEventAggregator eventAggregator,
IMenuItemCollectionFactory menuItemCollectionFactory)
: base(textService, umbracoApiControllerTypeCollection, eventAggregator)
{
_menuItemCollectionFactory = menuItemCollectionFactory;
}
protected override ActionResult<TreeNodeCollection?> GetTreeNodes(string id, FormCollection queryStrings)
protected override ActionResult<TreeNodeCollection> GetTreeNodes(string id, FormCollection queryStrings)
{
//We don't have any child nodes & only use the root node to load a custom UI
return new TreeNodeCollection();
}
protected override ActionResult<MenuItemCollection>? GetMenuForNode(string id, FormCollection queryStrings)
protected override ActionResult<MenuItemCollection> GetMenuForNode(string id, FormCollection queryStrings)
{
//We don't have any menu item options (such as create/delete/reload) & only use the root node to load a custom UI
return null;
return _menuItemCollectionFactory.Create();
}
/// <summary>

View File

@@ -17,24 +17,28 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
[CoreTree]
public class LogViewerTreeController : TreeController
{
private readonly IMenuItemCollectionFactory _menuItemCollectionFactory;
public LogViewerTreeController(
ILocalizedTextService localizedTextService,
UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection,
IEventAggregator eventAggregator)
IEventAggregator eventAggregator,
IMenuItemCollectionFactory menuItemCollectionFactory)
: base(localizedTextService, umbracoApiControllerTypeCollection, eventAggregator)
{
_menuItemCollectionFactory = menuItemCollectionFactory;
}
protected override ActionResult<TreeNodeCollection?> GetTreeNodes(string id, FormCollection queryStrings)
protected override ActionResult<TreeNodeCollection> GetTreeNodes(string id, FormCollection queryStrings)
{
//We don't have any child nodes & only use the root node to load a custom UI
return new TreeNodeCollection();
}
protected override ActionResult<MenuItemCollection>? GetMenuForNode(string id, FormCollection queryStrings)
protected override ActionResult<MenuItemCollection> GetMenuForNode(string id, FormCollection queryStrings)
{
//We don't have any menu item options (such as create/delete/reload) & only use the root node to load a custom UI
return null;
return _menuItemCollectionFactory.Create();
}
/// <summary>

View File

@@ -48,7 +48,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
return root;
}
protected override ActionResult<TreeNodeCollection?> GetTreeNodes(string id, FormCollection queryStrings)
protected override ActionResult<TreeNodeCollection> GetTreeNodes(string id, FormCollection queryStrings)
{
var nodes = new TreeNodeCollection();

View File

@@ -40,7 +40,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
_entityService = entityService;
}
protected override ActionResult<TreeNodeCollection?> GetTreeNodes(string id, FormCollection queryStrings)
protected override ActionResult<TreeNodeCollection> GetTreeNodes(string id, FormCollection queryStrings)
{
if (!int.TryParse(id, NumberStyles.Integer, CultureInfo.InvariantCulture, out var intId))
{

View File

@@ -104,7 +104,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
return node;
}
protected override ActionResult<TreeNodeCollection?> GetTreeNodes(string id, FormCollection queryStrings)
protected override ActionResult<TreeNodeCollection> GetTreeNodes(string id, FormCollection queryStrings)
{
var nodes = new TreeNodeCollection();

View File

@@ -52,7 +52,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
{
}
protected override ActionResult<TreeNodeCollection?> GetTreeNodes(string id, FormCollection queryStrings)
protected override ActionResult<TreeNodeCollection> GetTreeNodes(string id, FormCollection queryStrings)
{
var nodes = new TreeNodeCollection();

View File

@@ -56,7 +56,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
}
protected override ActionResult<TreeNodeCollection?> GetTreeNodes(string id, FormCollection queryStrings)
protected override ActionResult<TreeNodeCollection> GetTreeNodes(string id, FormCollection queryStrings)
{
//full screen app without tree nodes
return TreeNodeCollection.Empty;

View File

@@ -63,7 +63,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
return menu;
}
protected override ActionResult<TreeNodeCollection?> GetTreeNodes(string id, FormCollection queryStrings)
protected override ActionResult<TreeNodeCollection> GetTreeNodes(string id, FormCollection queryStrings)
{
var nodes = new TreeNodeCollection();

View File

@@ -16,18 +16,24 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
public class StaticFilesTreeController : TreeController
{
private readonly IFileSystem _fileSystem;
private readonly IMenuItemCollectionFactory _menuItemCollectionFactory;
private const string AppPlugins = "App_Plugins";
private const string Webroot = "wwwroot";
public StaticFilesTreeController(ILocalizedTextService localizedTextService,
UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, IEventAggregator eventAggregator,
IPhysicalFileSystem fileSystem) :
base(localizedTextService, umbracoApiControllerTypeCollection, eventAggregator)
public StaticFilesTreeController(
ILocalizedTextService localizedTextService,
UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection,
IEventAggregator eventAggregator,
IPhysicalFileSystem fileSystem,
IMenuItemCollectionFactory menuItemCollectionFactory)
: base(localizedTextService, umbracoApiControllerTypeCollection, eventAggregator)
{
_fileSystem = fileSystem;
_menuItemCollectionFactory = menuItemCollectionFactory;
}
protected override ActionResult<TreeNodeCollection?> GetTreeNodes(string id, FormCollection queryStrings)
protected override ActionResult<TreeNodeCollection> GetTreeNodes(string id, FormCollection queryStrings)
{
var path = string.IsNullOrEmpty(id) == false && id != Constants.System.RootString
? WebUtility.UrlDecode(id).TrimStart("/")
@@ -73,6 +79,6 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
}
// We don't have any menu item options (such as create/delete/reload) & only use the root node to load a custom UI
protected override ActionResult<MenuItemCollection>? GetMenuForNode(string id, FormCollection queryStrings) => null;
protected override ActionResult<MenuItemCollection> GetMenuForNode(string id, FormCollection queryStrings) => _menuItemCollectionFactory.Create();
}
}

View File

@@ -74,7 +74,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
/// We are allowing an arbitrary number of query strings to be pased in so that developers are able to persist custom data from the front-end
/// to the back end to be used in the query for model data.
/// </remarks>
protected override ActionResult<TreeNodeCollection?> GetTreeNodes(string id, FormCollection queryStrings)
protected override ActionResult<TreeNodeCollection> GetTreeNodes(string id, FormCollection queryStrings)
{
var nodes = new TreeNodeCollection();

View File

@@ -47,8 +47,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
/// We are allowing an arbitrary number of query strings to be passed in so that developers are able to persist custom data from the front-end
/// to the back end to be used in the query for model data.
/// </remarks>
[Obsolete("See GetTreeNodesAsync")]
protected abstract ActionResult<TreeNodeCollection?> GetTreeNodes(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))]FormCollection queryStrings);
protected abstract ActionResult<TreeNodeCollection> GetTreeNodes(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))]FormCollection queryStrings);
/// <summary>
/// Returns the menu structure for the node
@@ -56,8 +55,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
/// <param name="id"></param>
/// <param name="queryStrings"></param>
/// <returns></returns>
[Obsolete("See GetMenuForNodeAsync")]
protected abstract ActionResult<MenuItemCollection>? GetMenuForNode(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))]FormCollection queryStrings);
protected abstract ActionResult<MenuItemCollection> GetMenuForNode(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))]FormCollection queryStrings);
/// <summary>
/// The method called to render the contents of the tree structure
@@ -71,7 +69,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
/// We are allowing an arbitrary number of query strings to be passed in so that developers are able to persist custom data from the front-end
/// to the back end to be used in the query for model data.
/// </remarks>
protected virtual async Task<ActionResult<TreeNodeCollection?>> GetTreeNodesAsync(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))] FormCollection queryStrings)
protected virtual async Task<ActionResult<TreeNodeCollection>> GetTreeNodesAsync(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))] FormCollection queryStrings)
{
return GetTreeNodes(id, queryStrings);
}
@@ -85,7 +83,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
/// <remarks>
/// If overriden, GetMenuForNode will not be called
/// </remarks>
protected virtual async Task<ActionResult<MenuItemCollection>?> GetMenuForNodeAsync(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))] FormCollection queryStrings)
protected virtual async Task<ActionResult<MenuItemCollection>> GetMenuForNodeAsync(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))] FormCollection queryStrings)
{
return GetMenuForNode(id, queryStrings);
}

View File

@@ -53,7 +53,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
return root;
}
protected override ActionResult<TreeNodeCollection?> GetTreeNodes(string id, FormCollection queryStrings)
protected override ActionResult<TreeNodeCollection> GetTreeNodes(string id, FormCollection queryStrings)
{
//full screen app without tree nodes
return TreeNodeCollection.Empty;

View File

@@ -1,4 +1,4 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Umbraco.Cms.Core.Net;
using Umbraco.Cms.Core.Web;
@@ -14,7 +14,6 @@ namespace Umbraco.Cms.Web.Common.AspNetCore
_httpContextAccessor = httpContextAccessor;
}
/// <summary>
/// If session isn't enabled this will throw an exception so we check
/// </summary>
@@ -24,7 +23,7 @@ namespace Umbraco.Cms.Web.Common.AspNetCore
{
get
{
var httpContext = _httpContextAccessor?.HttpContext;
HttpContext? httpContext = _httpContextAccessor?.HttpContext;
return IsSessionsAvailable
? httpContext?.Session?.Id
@@ -32,17 +31,35 @@ namespace Umbraco.Cms.Web.Common.AspNetCore
}
}
public string? GetSessionValue(string sessionName)
public string? GetSessionValue(string key)
{
if(!IsSessionsAvailable) return null;
return _httpContextAccessor.HttpContext?.Session.GetString(sessionName);
if (!IsSessionsAvailable)
{
return null;
}
return _httpContextAccessor.HttpContext?.Session.GetString(key);
}
public void SetSessionValue(string sessionName, string value)
public void SetSessionValue(string key, string value)
{
if(!IsSessionsAvailable) return;
_httpContextAccessor.HttpContext?.Session.SetString(sessionName, value);
if (!IsSessionsAvailable)
{
return;
}
_httpContextAccessor.HttpContext?.Session.SetString(key, value);
}
public void ClearSessionValue(string key)
{
if (!IsSessionsAvailable)
{
return;
}
_httpContextAccessor.HttpContext?.Session.Remove(key);
}
}
}