SessionTracker 1.0.7
See the version list below for details.
dotnet add package SessionTracker --version 1.0.7
NuGet\Install-Package SessionTracker -Version 1.0.7
<PackageReference Include="SessionTracker" Version="1.0.7" />
paket add SessionTracker --version 1.0.7
#r "nuget: SessionTracker, 1.0.7"
// Install SessionTracker as a Cake Addin #addin nuget:?package=SessionTracker&version=1.0.7 // Install SessionTracker as a Cake Tool #tool nuget:?package=SessionTracker&version=1.0.7
SessionTracker
Library that allows working with "sessions".
Features
- Session tracking via starting, updating, finishing, fetching and fetching finished
Session
objects. - Configurable caching settings per
Session
type. - In-memory and Redis implementations provided out of the box.
Description
A session is encapsulated data that has to be passed around via an in-memory cache, a distributed cache or any other backing-store custom implementation. It is helpful when dealing with for example Discord API interactions that may need some data passed between them without relying on Discords custom ID.
Installation
To register the session tracker service use the following extension methods:
For base in-memory implementation:
services.AddSessionTracker(options);
For Redis implementation:
builder.AddRedisSessionTracker(options, redisOptions);
If you wish to configure the JsonSerializerOptions
used for serializing/deserializing session instances within Redis provider use:
services.Configure<JsonSerializerOptions>(SessionSettings.JsonSerializerName, yourOptions);
You can implement your own backing store provider by implementing ISessionsBackingStoreProvider
interface and registering your new service with the container like so:
services.AddSingleton<ISessionsBackingStoreProvider, YourImplementationType>;
Example usage
Create your own Session
type:
public CustomSession : Session
{
public bool IsThisASuperSession { get; set; }
public CustomSession(bool isSuper = true)
=> IsThisASuperSession = isSuper;
}
Inject ISessionTracker
to your handlers/services/controllers/whatnot:
Start session inside one handler:
public FirstSimpleInteractionHandler
{
private readonly ISessionTracker _tracker;
public FirstSimpleInteractionHandler(ISessionTracker tracker)
=> _tracker = tracker;
void Handle()
{
string key = "superKeyForThisSession";
var session = new CustomSession(false);
await _tracker.StartSessionAsync<CustomSession>(key, session);
}
}
Update from another:
public SecondSimpleInteractionHandler
{
private readonly ISessionTracker _tracker;
public SecondSimpleInteractionHandler(ISessionTracker tracker)
=> _tracker = tracker;
void Handle()
{
string key = "superKeyForThisSession"
var result = await _tracker.GetSessionAsync<CustomSession>(key);
if (!result.IsDefined(out var session))
return;
result.IsThisASuperSession = false;
await _tracker.UpdateSessionAsync<CustomSession>(key, result);
}
}
Use in third:
public ThirdSimpleInteractionHandler
{
private readonly ISessionTracker _tracker;
public ThirdSimpleInteractionHandler(ISessionTracker tracker)
=> _tracker = tracker;
void Handle()
{
string key = "superKeyForThisSession"
var result = await _tracker.GetSessionAsync<CustomSession>(key);
if (!result.IsDefined(out var session))
return;
var check = result.IsThisASuperSession // returns false
}
}
Finalize in fourth:
public FourthSimpleInteractionHandler
{
private readonly ISessionTracker _tracker;
public FourthSimpleInteractionHandler(ISessionTracker tracker)
=> _tracker = tracker;
void Handle()
{
string key = "superKeyForThisSession"
await _tracker.FinishSessionAsync<CustomSession>(key);
}
}
Get from finalized cache in fifth:
public FifthSimpleInteractionHandler
{
private readonly ISessionTracker _tracker;
public FifthSimpleInteractionHandler(ISessionTracker tracker)
=> _tracker = tracker;
void Handle()
{
string key = "superKeyForThisSession"
// note that using GetSessionAsync here would result in a NotFoundError
var result = await _tracker.GetFinishedSessionAsync<CustomSession>(key);
if (!result.IsDefined(out var session))
return;
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- JetBrains.Annotations (>= 2022.1.0)
- Microsoft.Extensions.Caching.Memory (>= 6.0.1)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 6.0.8)
- Remora.Results (>= 7.2.2)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on SessionTracker:
Package | Downloads |
---|---|
SessionTracker.Redis
Sub library that adds Redis backing-store implementation for the SessionTracker. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.0.15 | 422 | 1/9/2023 |
2.0.14 | 358 | 1/9/2023 |
2.0.13 | 412 | 11/19/2022 |
2.0.12 | 417 | 11/19/2022 |
2.0.11 | 508 | 9/6/2022 |
2.0.9 | 502 | 9/4/2022 |
2.0.8 | 489 | 9/4/2022 |
2.0.7 | 503 | 9/4/2022 |
2.0.6 | 500 | 9/4/2022 |
2.0.5 | 495 | 9/4/2022 |
2.0.4 | 511 | 9/4/2022 |
2.0.3 | 505 | 9/4/2022 |
2.0.2 | 492 | 9/4/2022 |
2.0.1 | 500 | 9/3/2022 |
2.0.0 | 395 | 9/3/2022 |
1.1.13 | 431 | 8/30/2022 |
1.1.12 | 388 | 8/30/2022 |
1.1.11 | 386 | 8/30/2022 |
1.1.10 | 386 | 8/30/2022 |
1.1.9 | 380 | 8/30/2022 |
1.1.8 | 402 | 8/29/2022 |
1.1.7 | 393 | 8/29/2022 |
1.1.6 | 394 | 8/29/2022 |
1.1.5 | 399 | 8/29/2022 |
1.1.4 | 384 | 8/29/2022 |
1.1.3 | 395 | 8/29/2022 |
1.1.2 | 401 | 8/29/2022 |
1.1.1 | 405 | 8/29/2022 |
1.1.0 | 389 | 8/29/2022 |
1.0.20 | 393 | 8/29/2022 |
1.0.19 | 404 | 8/29/2022 |
1.0.18 | 380 | 8/29/2022 |
1.0.17 | 378 | 8/29/2022 |
1.0.16 | 383 | 8/29/2022 |
1.0.15 | 367 | 8/29/2022 |
1.0.14 | 382 | 8/28/2022 |
1.0.13 | 375 | 8/28/2022 |
1.0.12 | 395 | 8/28/2022 |
1.0.11 | 394 | 8/28/2022 |
1.0.10 | 381 | 8/28/2022 |
1.0.9 | 386 | 8/28/2022 |
1.0.8 | 391 | 8/27/2022 |
1.0.7 | 389 | 8/27/2022 |
1.0.6 | 389 | 8/27/2022 |
1.0.5 | 401 | 8/27/2022 |
1.0.4 | 395 | 8/27/2022 |
1.0.3 | 377 | 8/27/2022 |
1.0.2 | 402 | 8/27/2022 |
1.0.1 | 395 | 8/27/2022 |
1.0.0 | 421 | 8/27/2022 |