项目作者: danieljsummers

项目描述 :
A framework for Nancy to allow persistent sessions and strongly-typed access to session values
高级语言: F#
项目地址: git://github.com/danieljsummers/Nancy.Session.Persistable.git
创建时间: 2016-06-30T23:56:00Z
项目社区:https://github.com/danieljsummers/Nancy.Session.Persistable

开源协议:MIT License

下载


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.

" class="reference-link">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#…

  1. namespace ExampleNancyApp
  2. {
  3. using Nancy;
  4. using Nancy.Bootstrapper;
  5. using Nancy.Session.Persistable;
  6. using Nancy.TinyIoc;
  7. public class ApplicationBootstrapper : DefaultNancyBootstrapper
  8. {
  9. protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
  10. {
  11. base.ApplicationStartup(container, pipelines);
  12. // Enable sessions
  13. PersistableSessions.Enable(pipelines, [config]);
  14. }
  15. }
  16. }

… or F# …

  1. module ExampleNancyApp
  2. open Nancy
  3. open Nancy.Bootstrapper
  4. open Nancy.Session.Persistable
  5. type ApplicationBootstrapper() =
  6. inherit DefaultNancyBootstrapper()
  7. override this.ApplicationStartup (container, pipelines) =
  8. base.ApplicationStartup (container, pipelines)
  9. // Enable sessions
  10. PersistableSessions.Enable (pipelines, [config])

… or even Visual Basic.NET!

  1. Imports Nancy
  2. Imports Nancy.Bootstrapper
  3. Imports Nancy.Session.Persistable
  4. Imports Nancy.TinyIoc
  5. Namespace ExampleNancyApp
  6. Public Class ApplicationBootstrapper
  7. Inherits DefaultNancyBootstrapper
  8. Protected Overrides Sub ApplicationStartup(container As TinyIoCContainer, pipelines As IPipelines)
  9. MyBase.ApplicationStartup(container, pipelines)
  10. ' Enable sessions
  11. PersistableSessions.Enable(pipelines, [config])
  12. End Sub
  13. End Class
  14. 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.