Jasper.Persistence.Marten Edit on GitHub

Note! The Jasper.Persistence.Marten has a dependency on the lower level Jasper.Persistence.Postgresql Nuget library.

The Jasper.Persistence.Marten library provides some easy to use recipes for integrating Marten and Postgresql into a Jasper application. All you need to do to get started with Marten + Jasper is to add the Jasper.Persistence.Marten nuget to your project and at minimum, at least set the connection string to the underlying Postgresql database by configuring Marten's StoreOptions object like this:

public class AppWithMarten : JasperRegistry
    public AppWithMarten()
        // StoreOptions is a Marten object that fulfills the same
        // role as JasperRegistry
        Settings.ConfigureMarten((context, marten) =>
            // At the simplest, you would just need to tell Marten
            // the connection string to the application database

Note that ConfigureMarten() is an extension method in Jasper.Marten.

Once that's done, you will be able to inject the following Marten services as either constructor arguments or method parameters in message or HTTP handlers:

  1. IDocumentStore
  2. IDocumentSession - opened with the default IDocumentStore.OpenSession() method
  3. IQuerySession

Likewise, all of these service will be registered in the underlying IoC container for the application.

If you need to customize an IDocumentSession for something like transaction levels or automatic dirty checking, we recommend that you just take in IDocumentStore and create the session in the application code.

As an example:

public class UsingDocumentSessionHandler
    // Take in IDocumentStore as a constructor argument
    public UsingDocumentSessionHandler(IDocumentStore store)

    // Take in IDocumentSession as an argument
    public void Handle(Message1 message, IDocumentSession session)

On top of the auto-discovered Marten service integration, the Jasper.Persistence.Marten extension also has: