it would be simpler to just pass session to the class:
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Session;
namespace RazorPagesMovie.Helpers
{
public class Chk
{
ISession session;
public Chk(ISession session)
{
this.session = session;
}
public void Foo()
{
session?.SetString("Name", "Bobby");
session?.SetInt32("Age", 773);
}
public void getFoo()
{
session?.GetString("Name");
session?.SetInt32("Age", 773);
}
}
}
in a page you create
Chk chk = new Chk(HttpContext.Session);
or create a session extension class
public static class SessionExtensions
{
public static string? GetFoo (this ISession session) => return session["foo"];
public static void SetFoo(this ISession session, string value) => session["foo"] = value;
}
and use
var foo = HttpContext.Session?.GetFoo();