Jasper.Marten Edit on GitHub


The Jasper.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.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
            marten.Connection(context.Configuration.GetConnectionString("marten"));
        });
    }
}

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.Marten extension also has: