-
Notifications
You must be signed in to change notification settings - Fork 0
Session Extensions
ASP.NET Core Session Helpers and Extensions powered by MessagePack
This library fills in the gaps of not-implemented methods of ISession in ASP.NET Core.
ISession gets and sets arrays of the byte as a basic data structure and for converting all kinds of other data-types (to and from bytes) we use MessagePack (for object data-type) and BitConverter (for primitive data-types).
The extremely fast MessagePack serializer for C#. It is 10x faster than MsgPack-Cli and outperforms other C# serializers. MessagePack for C# also ships with built-in support for LZ4 compression - an extremely fast compression algorithm. Performance is important, particularly in applications like game development, distributed computing, microservice architecture, and caching.
You should install Alamut.Extensions.Session with NuGet:
Install-Package Alamut.Extensions.Session
Or via the .NET Core command-line interface:
dotnet add package Alamut.Extensions.Session
Either commands, from Package Manager Console or .NET Core CLI, will download and install all required dependencies.
By calling the SerializerProvider.SetDefaultSerializer()
at the startup of your app you can change the default serializer.
more info
Provides extension methods to set and get primitive data-types (powered by BitConverter)
Support Types:
- bool
- char
- double
- short
- int
- long
- float
- ushort
- uint
- ulong
- DateTime
Samples:
// arrange
var key = "foo-bool";
var expected = true;
// act
_session.Set(key, expected);
var actual = _session.GetBool(key);
// assert
Assert.Equal(expected, actual);
Provides extension methods to set and get object data-type
Methods:
void Set<T>(this ISession session, string key, T value)
T Get<T>(this ISession session, string key)
bool TryGetValue<T>(this ISession session, string key, out T value)
Samples:
//Given
const string key = "tryGetValue-test";
var expected = new RefTypeObject
{
foo = 1,
bar = "test",
Created = DateTime.UtcNow
};
_session.Set(key, expected);
//When
var result = _session.TryGetValue<RefTypeObject>(key, out var actual);
//Then
Assert.Equal(expected, actual);