Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

A framework for Nancy to allow persistent sessions and strongly-typed access to session values

License

Notifications You must be signed in to change notification settings

danieljsummers/Nancy.Session.Persistable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NOTE (April 2024)

The Nancy project is no longer active; this project has followed its lead.

Nancy.Session.Persistable

This is a community project that provides several session store implementations for Nancy, the lean-and-mean web framework that runs under the .NET framework. It also provides extensions to the Nancy Request object that allow strongly-typed retrieval of objects from the session. It uses cookies to associate the session Id with a request.

Get It NuGet Version Build status

The Nancy.Session.Persistable pacakge will be installed when you install any of the available back-end storage packages. Currently available:

Data Store Docs Package Stable (Nancy v2)
Relational Wiki NuGet NuGet Version
RavenDB Wiki NuGet NuGet Version
RethinkDB Wiki NuGet NuGet Version
MongoDB Wiki NuGet NuGet Version
In Memory Wiki NuGet NuGet Version

NOTE: While the API is currently thought stable, it may change up until a 1.0 release.

NOTE 2: Possible future implementations include Redis and disk storage.

Enable It

To enable sessions, you have to override the default Nancy bootstrapper. This sounds way scarier than it actually is; you can do it in just a few lines of code. Following their lead, persistable sessions are fully SDHP-compliant.

You can do it in C#...

namespace ExampleNancyApp
{
    using Nancy;
    using Nancy.Bootstrapper;
    using Nancy.Session.Persistable;
    using Nancy.TinyIoc;

    public class ApplicationBootstrapper : DefaultNancyBootstrapper
    {
        protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
        {
            base.ApplicationStartup(container, pipelines);

            // Enable sessions
            PersistableSessions.Enable(pipelines, [config]);
        }
    }
}

... or F# ...

module ExampleNancyApp

open Nancy
open Nancy.Bootstrapper
open Nancy.Session.Persistable

type ApplicationBootstrapper() =
  inherit DefaultNancyBootstrapper()
  override this.ApplicationStartup (container, pipelines) =
    base.ApplicationStartup (container, pipelines)
    // Enable sessions
    PersistableSessions.Enable (pipelines, [config])

... or even Visual Basic.NET!

Imports Nancy
Imports Nancy.Bootstrapper
Imports Nancy.Session.Persistable
Imports Nancy.TinyIoc

Namespace ExampleNancyApp

    Public Class ApplicationBootstrapper
        Inherits DefaultNancyBootstrapper

        Protected Overrides Sub ApplicationStartup(container As TinyIoCContainer, pipelines As IPipelines)
            MyBase.ApplicationStartup(container, pipelines)
            ' Enable sessions
            PersistableSessions.Enable(pipelines, [config])
        End Sub

    End Class

End Namespace

The store-specific [config] object is detailed in each implementation project. Each of these objects takes an optional Nancy.Cryptography.CryptographyConfiguration parameter that is used to control the cryptography used for the session Id cookie. If it is not specified, it uses a default configuration.

Retrieving the current session needs to happen early in the request cycle, and persisting it needs to happen as late as possible. So, in your bootstrapper, put the PersistableSessions.Enable call as late as possible.

Configuration and Use

Common and implementation-specific configuration options and usage can be found in the wiki.

About

A framework for Nancy to allow persistent sessions and strongly-typed access to session values

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages