<commit_before>---
title: Changing Persistence in a ServiceMatrix Project
summary: 'Selecting a persistence store within a ServiceMatrix project.'
tags:
- ServiceMatrix
- Persistence
---

NServiceBus requires a persistence store. By default, ServiceMatrix provisions your solution to use the `InMemoryPersistence` class, but only if the Visual Studio debugger is attached. If you attempt to run your project without the debugger attached, you will receive an exception informing you to choose a durable persistence class.

NServiceBus offers multiple options for different persistence technologies. Please read [Persistence In NServiceBus](../nservicebus/persistence-in-nservicebus.md) for an overview. The example below shows how to setup the RavenDB persistence store, but a similar process can be used for the other stores. 

1.  [Installing the RavenDB NuGet Package](#installing-the-ravendb-nuget-package)  
2.  [Selecting Persistence for an ASP.NET MVC Endpoint](#selecting-persistence-for-an-asp-net-mvc-endpoint)
3.  [Selecting Persistence for an NSB Host Endpoint](#selecting-persistence-for-an-nsb-host-endpoint)
4.  [Installing RavenDB 2.5](#installing-ravendb-2-5)

# Installing the RavenDB NuGet Package

Regardless of what type of endpoint you have, you will need to install the NuGet package containing the classes for the persistence store you are planning to use. Right-click on your project in the Solution Explorer and select 'Manage NuGet Packages...' Search Online for the `NServiceBus.RavenDB` package and install it.

![NServiceBus.RavenDB NuGet Package](images/servicematrix-ravendb-nuget.png)

# Selecting Persistence for an ASP.NET MVC Endpoint

For an ASP.NET MVC endpoint, you will find the setup in `Infrastructure\WebGlobalInitialization.cs`. 

````C#
if (Debugger.IsAttached)
{
    // For production use, please select a durable persistence.
    // To use RavenDB, install-package NServiceBus.RavenDB and then use configuration.UsePersistence<RavenDBPersistence>();
    // To use SQLServer, install-package NServiceBus.NHibernate and then use configuration.UsePersistence<NHibernatePersistence>();    
    config.UsePersistence<InMemoryPersistence>();
...
````

Because `Infrastructure\WebGlobalInitialization.cs` is an auto-generated code file by ServiceMatrix, you should not edit it directly (or else your changes will be gone the next time it is rebuilt). Instead, add a new class file named `ConfigurePersistence.cs` to the Infrastructure folder of the ASP.NET project. Update it to initialize the RavenDBPersistence class as follows:

````C#
using NServiceBus;
using NServiceBus.Persistence;

namespace OnlineSalesV5.eCommerce.Infrastructure
{
    public class ConfigurePersistence : INeedInitialization
    {
        public void Customize(BusConfiguration config)
        {
            config.UsePersistence<RavenDBPersistence>();
        }
    }
}
````

# Selecting Persistence for an NSB Host Endpoint

In your NSB Host endpoints, you will find the setup in `EndpointConfig.cs`.

````C#
// For production use, please select a durable persistence.
// To use RavenDB, install-package NServiceBus.RavenDB and then use configuration.UsePersistence<RavenDBPersistence>();
// To use SQLServer, install-package NServiceBus.NHibernate and then use configuration.UsePersistence<NHibernatePersistence>();
if (Debugger.IsAttached)
{
    configuration.UsePersistence<InMemoryPersistence>();
}
````

Modify the code in `EndpointConfig.cs`.

````C#
using NServiceBus;
using NServiceBus.Persistence;
 
namespace OnlineSales.OrderProcessing
{
    public partial class EndpointConfig    
    {
        public void Customize(BusConfiguration configuration)
        {
            configuration.UsePersistence<RavenDBPersistence>();
        }
    }
}
````

# Installing RavenDB 2.5

An NServiceBus V5 ServiceMatrix project requires RavenDB V2.5. Download the installer from [ravendb.net](http://ravendb.net/download) and select "Development" for the target environment.

NOTE: If you already have RavenDB 2.0 installed, you can uninstall the service by finding the Raven.Server.exe executable on your machine and running it from the command line with /uninstall.

For more information on installing RavenDB for use with NService bus, refer to [this document](/nservicebus/using-ravendb-in-nservicebus-installing.md).

Return to the ServiceMatrix [table of contents](./).<commit_msg>ServiceMatrix persistence updates: package console, RavenDB version clarifications<commit_after>---
title: Changing Persistence in a ServiceMatrix Project
summary: 'Selecting a persistence store within a ServiceMatrix project.'
tags:
- ServiceMatrix
- Persistence
---

NServiceBus requires a persistence store. By default, ServiceMatrix provisions your solution to use the `InMemoryPersistence` class, but only if the Visual Studio debugger is attached. If you attempt to run your project without the debugger attached, you will receive an exception informing you to choose a durable persistence class.

NServiceBus offers multiple options for different persistence technologies. Please read [Persistence In NServiceBus](../nservicebus/persistence-in-nservicebus.md) for an overview. The example below shows how to setup the RavenDB persistence store, but a similar process can be used for the other stores. 

1.  [Installing the RavenDB NuGet Package](#installing-the-ravendb-nuget-package)  
2.  [Selecting Persistence for an ASP.NET MVC Endpoint](#selecting-persistence-for-an-asp-net-mvc-endpoint)
3.  [Selecting Persistence for an NSB Host Endpoint](#selecting-persistence-for-an-nsb-host-endpoint)
4.  [Installing RavenDB 2.5](#installing-ravendb-2-5)

# Installing the RavenDB NuGet Package

Regardless of what type of endpoint you have, you will need to install the NuGet package containing the classes for the persistence store you are planning to use.

Open the NuGet Package Manager Console: `Tools > NuGet Package Manager > Package Manager Console`.

Type the following command at the Package Manager Console:

    PM> Install-Package NServiceBus.RavenDB

NOTE: When prompted to reload the project, click reload

# Selecting Persistence for an ASP.NET MVC Endpoint

For an ASP.NET MVC endpoint, you will find the setup in `Infrastructure\WebGlobalInitialization.cs`. 

````C#
if (Debugger.IsAttached)
{
    // For production use, please select a durable persistence.
    // To use RavenDB, install-package NServiceBus.RavenDB and then use configuration.UsePersistence<RavenDBPersistence>();
    // To use SQLServer, install-package NServiceBus.NHibernate and then use configuration.UsePersistence<NHibernatePersistence>();    
    config.UsePersistence<InMemoryPersistence>();
...
````

Because `Infrastructure\WebGlobalInitialization.cs` is an auto-generated code file by ServiceMatrix, you should not edit it directly (or else your changes will be gone the next time it is rebuilt). Instead, add a new class file named `ConfigurePersistence.cs` to the Infrastructure folder of the ASP.NET project. Update it to initialize the RavenDBPersistence class as follows:

````C#
using NServiceBus;
using NServiceBus.Persistence;

namespace OnlineSalesV5.eCommerce.Infrastructure
{
    public class ConfigurePersistence : INeedInitialization
    {
        public void Customize(BusConfiguration config)
        {
            config.UsePersistence<RavenDBPersistence>();
        }
    }
}
````

# Selecting Persistence for an NSB Host Endpoint

In your NSB Host endpoints, you will find the setup in `EndpointConfig.cs`.

````C#
// For production use, please select a durable persistence.
// To use RavenDB, install-package NServiceBus.RavenDB and then use configuration.UsePersistence<RavenDBPersistence>();
// To use SQLServer, install-package NServiceBus.NHibernate and then use configuration.UsePersistence<NHibernatePersistence>();
if (Debugger.IsAttached)
{
    configuration.UsePersistence<InMemoryPersistence>();
}
````

Modify the code in `EndpointConfig.cs`.

````C#
using NServiceBus;
using NServiceBus.Persistence;
 
namespace OnlineSales.OrderProcessing
{
    public partial class EndpointConfig    
    {
        public void Customize(BusConfiguration configuration)
        {
            configuration.UsePersistence<RavenDBPersistence>();
        }
    }
}
````

# Installing RavenDB 2.5

If you are using RavenDB peristence and NServiceBus V5 you will need RavenDB **V2.5**. Download the installer from [ravendb.net](http://ravendb.net/download) and select "Development" for the target environment.

NOTE: Versions V4 and earlier of NServiceBus used an older version of RavenDB. If you already have RavenDB 2.0 installed, you can uninstall the service by finding the Raven.Server.exe executable on your machine and running it from the command line with /uninstall.

For more information on installing RavenDB for use with NService bus and the different version-specific requirements, refer to [this document](/nservicebus/using-ravendb-in-nservicebus-installing.md).

Return to the ServiceMatrix [table of contents](./).
{'fraction_non_alphanumeric': 0.07475395333407055, 'fraction_numerical': 0.0036492314497401303, 'mean_word_length': 4.613904407200496, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6529327', 'n_tokens_mistral': 2475, 'n_tokens_neox': 2346, 'n_words': 946}