SessionTracker 2.0.15

dotnet add package SessionTracker --version 2.0.15
NuGet\Install-Package SessionTracker -Version 2.0.15
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SessionTracker" Version="2.0.15" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SessionTracker --version 2.0.15
#r "nuget: SessionTracker, 2.0.15"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SessionTracker as a Cake Addin
#addin nuget:?package=SessionTracker&version=2.0.15

// Install SessionTracker as a Cake Tool
#tool nuget:?package=SessionTracker&version=2.0.15

SessionTracker

Build Status

Library that allows working with distributed "sessions".

Features

  • Session tracking via starting, updating, finishing, resuming, locking and fetching finished Session objects.
  • Configurable caching settings per Session type.
  • Redis implementations provided out of the box.

Description

A session is encapsulated data that has to be passed around 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 while there are multiple service instances.

Installation

To register the session tracker service use the following extension methods:

For base services with no backing-store implementation registration:

builder.AddSessionTracker(options);

For Redis implementation:

builder.AddRedisSessionTracker(redisOptions, options);

If you wish to configure the JsonSerializerOptions used for serializing/deserializing session instances within Redis provider use:

services.Configure<JsonSerializerOptions>(RedisSessionSettings.JsonSerializerName, yourOptions);

You can implement your own backing store provider and lock provider by implementing ISessionTrackerDataProvider or ISessionLockProvder interfaces respectively and registering your new services with the container like so:

services.AddSessionTrackerDataProvider<YourDataProviderType>();
services.AddSessionTrackerLockProvider<YourLockProviderType>();

// or 

services.AddSessionTrackerDataProvider(AnInstanceOfYourDataProvider);
services.AddSessionTrackerLockProvider(AnInstanceOfYourLockProvider);

These will overwrite any other provider implementation currently registered with the container.

Example usage

Create your own Session type:

public CustomSession : Session
{
    public bool IsThisASuperSession { get; set; }
    
    public CustomSession(string key, bool isSuper = true) : base(key)
        => 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()
    {
        var session = new CustomSession("superKeyForThisSession", false);

        var result = await _tracker.StartAsync(session);
        if (!result.IsSuccess)
            return;
    }
}

Update from another:

public SecondSimpleInteractionHandler
{
    private readonly ISessionTracker _tracker;

    public SecondSimpleInteractionHandler(ISessionTracker tracker)
        => _tracker = tracker;

    void Handle()
    {
        var result = await _tracker.GetLockedAsync<CustomSession>("superKeyForThisSession");
        if (!result.IsDefined(out var lockedSession))
            return;

        await using var @lock = lockedSession.Lock;

        lockedSession.Session.IsThisASuperSession = true;

        await _tracker.UpdateSessionAsync(lockedSession.Session);
    }
}

Finalize in fourth:

public FourthSimpleInteractionHandler
{
    private readonly ISessionTracker _tracker;

    public FourthSimpleInteractionHandler(ISessionTracker tracker)
        => _tracker = tracker;

    void Handle()
    {
        await _tracker.FinishAsync<CustomSession>("superKeyForThisSession");
    }
}
Product 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 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 354 1/9/2023
2.0.14 320 1/9/2023
2.0.13 370 11/19/2022
2.0.12 369 11/19/2022
2.0.11 468 9/6/2022
2.0.9 463 9/4/2022
2.0.8 456 9/4/2022
2.0.7 462 9/4/2022
2.0.6 458 9/4/2022
2.0.5 459 9/4/2022
2.0.4 471 9/4/2022
2.0.3 464 9/4/2022
2.0.2 450 9/4/2022
2.0.1 464 9/3/2022
2.0.0 361 9/3/2022
1.1.13 372 8/30/2022
1.1.12 352 8/30/2022
1.1.11 350 8/30/2022
1.1.10 348 8/30/2022
1.1.9 351 8/30/2022
1.1.8 358 8/29/2022
1.1.7 360 8/29/2022
1.1.6 362 8/29/2022
1.1.5 366 8/29/2022
1.1.4 347 8/29/2022
1.1.3 359 8/29/2022
1.1.2 359 8/29/2022
1.1.1 359 8/29/2022
1.1.0 353 8/29/2022
1.0.20 361 8/29/2022
1.0.19 366 8/29/2022
1.0.18 343 8/29/2022
1.0.17 348 8/29/2022
1.0.16 345 8/29/2022
1.0.15 329 8/29/2022
1.0.14 348 8/28/2022
1.0.13 352 8/28/2022
1.0.12 358 8/28/2022
1.0.11 358 8/28/2022
1.0.10 344 8/28/2022
1.0.9 357 8/28/2022
1.0.8 353 8/27/2022
1.0.7 352 8/27/2022
1.0.6 352 8/27/2022
1.0.5 362 8/27/2022
1.0.4 357 8/27/2022
1.0.3 359 8/27/2022
1.0.2 365 8/27/2022
1.0.1 360 8/27/2022
1.0.0 388 8/27/2022