Skip to content
On this page

Integration and Configuration

To add Marten to a .Net project, first go get the Marten library from Nuget:

Using .NET CLI

shell
dotnet add package Marten

Or, using PowerShell

powershell
PM> Install-Package Marten

Or, using Paket:

shell
paket add nuget Marten

The next step is to get access to a PostgreSQL 9.6+ database schema. If you want to let Marten build database schema objects on the fly at development time, make sure that your user account has rights to execute CREATE TABLE/FUNCTION statements.

Marten uses the Npgsql library to access PostgreSQL from .NET, so you'll likely want to read their documentation on connection string syntax.

TIP

Remember the movie Highlander? In the case of DocumentStore, there should be only one. DocumentStore is an expensive object to create that tracks any necessary development time database changes and also stores all the dynamically created runtime objects that Marten needs to use at runtime.

To start up Marten in a running application, you need to create a single IDocumentStore object. The quickest possible way is to start with all the default behavior and a connection string to a Postgresql database:

cs
var store = DocumentStore
    .For("host=localhost;database=marten_testing;password=mypassword;username=someuser");

snippet source | anchor

Most of the time however, you'll need to configure more options and integrate Marten into a .Net application. For most applications, you'll want to use Marten's IServiceCollection extensions to integrate with your application. If you're eschewing the .Net HostBuilder/WebHostBuilder, see Do It Yourself IoC Integration.

For more information about Marten's configuration options, see Working with StoreOptions.

Released under the MIT License.