Repository navigation
#4867 Add Azure Table Storage ISessionStore package #4957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rockfordlhotka
merged 6 commits into
MarimerLLC:main
from
joshhanson314:feature/4867-azure-table-storage-sessionstore
Nov 2, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d0bf0de
#4867 Add Azure Table Storage ISessionStore package
joshhanson314 eb6768f
#4867 Address review feedback on the Azure Table Storage session store
joshhanson314 032430a
Merge branch 'main' into feature/4867-azure-table-storage-sessionstore
joshhanson314 db28cdc
#4867 Stop serializing live sessions during purge and split large ses…
joshhanson314 9bfdb4c
Merge remote-tracking branch 'origin/main' into pr-4957
rockfordlhotka b83d924
#4867 Address Stefan's review of the Azure Table Storage session store
rockfordlhotka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
Source/Csla.Blazor.State.AzureTableStorage/AzureTableStorageConfigurationExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| //----------------------------------------------------------------------- | ||
| // <copyright file="AzureTableStorageConfigurationExtensions.cs" company="Marimer LLC"> | ||
| // Copyright (c) Marimer LLC. All rights reserved. | ||
| // Website: https://cslanet.com | ||
| // </copyright> | ||
| // <summary>Configuration extensions for the Azure Table Storage session store</summary> | ||
| //----------------------------------------------------------------------- | ||
|
|
||
| using Azure.Data.Tables; | ||
| using Csla.Blazor.State.AzureTableStorage; | ||
| using Csla.State; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.DependencyInjection.Extensions; | ||
|
|
||
| namespace Csla.Configuration | ||
| { | ||
| /// <summary> | ||
| /// Implement extension methods to register the Azure Table Storage | ||
| /// session store with the CSLA configuration system. | ||
| /// </summary> | ||
| public static class AzureTableStorageConfigurationExtensions | ||
| { | ||
| /// <summary> | ||
| /// Configures CSLA to use the Azure Table Storage | ||
| /// <see cref="ISessionStore"/> implementation. | ||
| /// </summary> | ||
| /// <param name="config">The <see cref="CslaOptions"/> instance.</param> | ||
| /// <param name="options">An optional delegate to configure the store.</param> | ||
| /// <returns>The <see cref="CslaOptions"/> instance.</returns> | ||
| /// <remarks> | ||
| /// Call this after <c>AddServerSideBlazor</c>, which registers the default | ||
| /// in-memory session store; the last registration wins. The session store | ||
| /// is only used when <c>UseInMemoryApplicationContextManager</c> is | ||
| /// <see langword="false"/>. Call <see cref="ISessionManager.PurgeSessions"/> | ||
| /// periodically: besides removing expired sessions, it refreshes the stored | ||
| /// last-touched time of live sessions, so other servers do not purge them. | ||
| /// <para> | ||
| /// Live sessions are kept in memory. Session data is written to the table | ||
| /// when a session is saved through <see cref="ISessionManager.UpdateSession"/>, | ||
| /// such as when the WebAssembly client sends its state; changes made in | ||
| /// place are written with the next save. A session can serialize to at | ||
| /// most 704 KiB. | ||
| /// </para> | ||
| /// <para> | ||
| /// The <see cref="TableServiceClient"/> comes from | ||
| /// <see cref="AzureTableStorageOptions.ConnectionString"/> when it is set, | ||
| /// otherwise from the keyed service named by | ||
| /// <see cref="AzureTableStorageOptions.ServiceKey"/>, otherwise from the | ||
| /// default <see cref="TableServiceClient"/> registered in the container. | ||
| /// </para> | ||
| /// </remarks> | ||
| /// <exception cref="ArgumentNullException"><paramref name="config"/> is <see langword="null"/>.</exception> | ||
| public static CslaOptions UseAzureTableStorageSessionStore(this CslaOptions config, Action<AzureTableStorageOptions>? options = null) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(config); | ||
|
|
||
| var storeOptions = new AzureTableStorageOptions(); | ||
| options?.Invoke(storeOptions); | ||
|
|
||
| // Singletons, because the singleton SessionManager depends on ISessionStore. | ||
| config.Services.AddSingleton(storeOptions); | ||
| config.Services.TryAddSingleton(TimeProvider.System); | ||
|
|
||
| // The client is resolved privately rather than registered, so the store | ||
| // never changes which TableServiceClient the rest of the app receives. | ||
| config.Services.AddSingleton<ISessionStore>(sp => | ||
| ActivatorUtilities.CreateInstance<AzureTableStorageSessionStore>( | ||
| sp, GetTableServiceClient(sp, sp.GetRequiredService<AzureTableStorageOptions>()))); | ||
| return config; | ||
| } | ||
|
|
||
| internal static TableServiceClient GetTableServiceClient(IServiceProvider serviceProvider, AzureTableStorageOptions options) | ||
| { | ||
| if (!string.IsNullOrEmpty(options.ConnectionString)) | ||
| return new TableServiceClient(options.ConnectionString); | ||
| if (options.ServiceKey is not null) | ||
| return serviceProvider.GetRequiredKeyedService<TableServiceClient>(options.ServiceKey); | ||
| return serviceProvider.GetRequiredService<TableServiceClient>(); | ||
| } | ||
| } | ||
| } | ||
52 changes: 52 additions & 0 deletions
52
Source/Csla.Blazor.State.AzureTableStorage/AzureTableStorageOptions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| //----------------------------------------------------------------------- | ||
| // <copyright file="AzureTableStorageOptions.cs" company="Marimer LLC"> | ||
| // Copyright (c) Marimer LLC. All rights reserved. | ||
| // Website: https://cslanet.com | ||
| // </copyright> | ||
| // <summary>Options for the Azure Table Storage session store</summary> | ||
| //----------------------------------------------------------------------- | ||
|
|
||
| namespace Csla.Blazor.State.AzureTableStorage; | ||
|
|
||
| /// <summary> | ||
| /// Options for configuring the Azure Table Storage | ||
| /// <see cref="Csla.State.ISessionStore"/> implementation. | ||
| /// </summary> | ||
| public class AzureTableStorageOptions | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the Azure Storage connection string used to | ||
| /// create the <see cref="Azure.Data.Tables.TableServiceClient"/>. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Leave <see langword="null"/> or empty to use a | ||
| /// <see cref="Azure.Data.Tables.TableServiceClient"/> that is already | ||
| /// registered in the dependency injection container (for example, one | ||
| /// registered by .NET Aspire or by managed-identity wiring). | ||
| /// </remarks> | ||
| public string? ConnectionString { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the dependency injection service key used to resolve a | ||
| /// keyed <see cref="Azure.Data.Tables.TableServiceClient"/>. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Set this when the host registered the client as a keyed service (for | ||
| /// example <c>builder.AddKeyedAzureTableClient("state")</c>). Ignored when | ||
| /// <see cref="ConnectionString"/> is supplied. | ||
| /// </remarks> | ||
| public object? ServiceKey { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the name of the Azure Storage table used to store | ||
| /// sessions. Defaults to <c>CslaStateSessionManager</c>. | ||
| /// </summary> | ||
| public string TableName { get; set; } = "CslaStateSessionManager"; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets a value used to discriminate sessions belonging to this | ||
| /// application when multiple applications share the same storage table. | ||
| /// Defaults to an empty string. | ||
| /// </summary> | ||
| public string ApplicationDiscriminator { get; set; } = string.Empty; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.