Skip to content

Abstract out session store from SessionManager#4567

Closed
joshhanson314 wants to merge 1 commit into
MarimerLLC:mainfrom
joshhanson314:dev/4565-state-management-session-store
Closed

Abstract out session store from SessionManager#4567
joshhanson314 wants to merge 1 commit into
MarimerLLC:mainfrom
joshhanson314:dev/4565-state-management-session-store

Conversation

@joshhanson314

@joshhanson314 joshhanson314 commented Mar 2, 2025

Copy link
Copy Markdown
Member

#4565 Added abstractions and a default implementation for a session store to be used with the Blazor state SessionManager. The default implementation continues to use in-memory persistence in a ConcurrentDictionary.

Added abstractions and a default implementation for a session store to be used with the Blazor state SessionManager. The default implementation continues to use in-memory persistence in a ConcurrentDictionary.
@joshhanson314 joshhanson314 changed the title #4565 Abstract out session store from SessionManager Abstract out session store from SessionManager Mar 2, 2025
@joshhanson314 joshhanson314 marked this pull request as ready for review March 2, 2025 17:37
@rockfordlhotka rockfordlhotka self-requested a review March 3, 2025 16:16

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @StefanOssendorf would be much happier if this had async methods instead of sync methods 😁

Seriously though, if we're going to improve the code like this, I do think we should expect that people will use async stores for the data.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please :)
You can always do sync with a Task/ValueTask method but not async with a void method :)

}

/// <inheritdoc />
public void DeleteSessions(SessionsFilter filter)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this method name. Perhaps it should be more explicit that this is expiring sessions?

/// </summary>
/// <param name="key"></param>
/// <param name="session"></param>
void CreateSession(string key, Session session);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the create/update be combined to a TryUpdate or something similar?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AddOrUpdate like the ConcurrentDictionary methods?

{
if (!Expiration.HasValue)
{
throw new ArgumentNullException("Expiration is required.");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No hard-coded use of English is allowed in the framework. This needs to be from a resource string or be ArgumentException(nameof(HasValue))

@ossendorf-at-hoelscher ossendorf-at-hoelscher Mar 4, 2025

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion to get rid of this exception would be: Don't allow the creation of an invalid object state.

  1. Make Expiration non nullable.
  2. Either add a constructor expecting the value and/or make the property required

With those changes the whole Validate() method becomes obsolete.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is basically internal to the default implementation right?

As in, if someone were to use a different session store they'd probably use their own approach for expiring old data.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Currently this class is part of the public API.
ISessionStore.DeleteSession(SessionsFilter)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really appreciate this refactoring - absolutely on the right track. While we're doing this, might as well also embrace async.

Perhaps also consider using file scoped namespaces so Simon doesn't need to come back later and clean that up?

ArgumentNullException.ThrowIfNull(newSession);
var key = _sessionIdManager.GetSessionId();
var existingSession = _sessions[key];
var existingSession = _sessionStore.GetSession(key)!;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you suppress with !? You should check for it and handle the default case.

@ossendorf-at-hoelscher

Copy link
Copy Markdown

@rockfordlhotka This is a change for v10. It's a breaking one ;)

@rockfordlhotka rockfordlhotka marked this pull request as draft July 21, 2025 20:42
@rockfordlhotka

Copy link
Copy Markdown
Member

Although this is a good change, I think this particular PR is so out of date now that it is beyond hope. If I'm wrong, please reopen and update, otherwise it'll stay closed.

joshhanson314 added a commit to joshhanson314/csla that referenced this pull request Feb 19, 2026
Added ISessionStore abstraction for Blazor SessionManager to support
load-balanced environments with pluggable session storage.

Addresses review feedback from PR MarimerLLC#4567:
- Async interface using ValueTask
- Combined Create/Update into AddOrUpdateSessionAsync
- Renamed DeleteSessions to PurgeExpiredSessionsAsync
- Removed SessionsFilter class
- File-scoped namespaces
- Proper null handling
rockfordlhotka pushed a commit that referenced this pull request Feb 19, 2026
* #4565 Abstract out session store from SessionManager

Added ISessionStore abstraction for Blazor SessionManager to support
load-balanced environments with pluggable session storage.

Addresses review feedback from PR #4567:
- Async interface using ValueTask
- Combined Create/Update into AddOrUpdateSessionAsync
- Renamed DeleteSessions to PurgeExpiredSessionsAsync
- Removed SessionsFilter class
- File-scoped namespaces
- Proper null handling

* Update Source/tests/Csla.test/State/SessionManagerTests.cs

Co-authored-by: Copilot <[email protected]>

* Update Source/tests/Csla.test/State/SessionManagerTests.cs

Co-authored-by: Copilot <[email protected]>

* #4565 Add input validation to InMemorySessionStore

Co-Authored-By: Claude Opus 4.6 <[email protected]>

---------

Co-authored-by: Copilot <[email protected]>
Co-authored-by: Claude Opus 4.6 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants