Skip to content

Commit

Permalink
RDoc-1706_certificatesCleanup - limit certificate cleanup explanation…
Browse files Browse the repository at this point in the history
… to versions under 6.0
  • Loading branch information
reebhub committed Dec 22, 2023
1 parent 97ada47 commit df93a0f
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ the store is disposed of, and use it to call the `Certificate.Dispose()` method.

{CODE certificate_cleanup@ClientApi\CreatingDocumentStore.cs /}

{NOTE: }
Note: In RavenDB `6.x` and on certificate cleanup is automatic and the procedure described here is unnecessary.
{NOTE/}

{PANEL/}

{PANEL: Creating a Document Store - Example}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ store event, triggered when the store is disposed of, and use it to call the `Ce

{CODE certificate_cleanup@ClientApi\CreatingDocumentStore.cs /}

{NOTE: }
Note: In RavenDB `6.x` and on certificate cleanup is automatic and the procedure described here is unnecessary.
{NOTE/}

{PANEL/}

{PANEL: Creating a Document Store - Example}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Client API: Creating a Document Store
---
{NOTE: }

* **Creating a Document Store** is the _first step_ that a RavenDB client application needs to make when working with RavenDB.

* We recommend that your Document Store implement the [Singleton Pattern](https://csharpindepth.com/articles/Singleton) as demonstrated in
the example code [below](../client-api/creating-document-store#creating-a-document-store---example).
Creating more than one Document Store may be resource intensive, and one instance is sufficient for most use cases.

* In this page:
* [Creating a Document Store - Configuration](../client-api/creating-document-store#creating-a-document-store---configuration)
* [Creating a Document Store - Example](../client-api/creating-document-store#creating-a-document-store---example)
{NOTE/}

---
{PANEL: Creating a Document Store - Configuration}

The following properties can be configured when creating a new Document Store:

* **Urls** (required)

* An initial URLs list of your RavenDB cluster nodes that is used when the client accesses the database for the _first_ time.

* Upon the first database access, the client will fetch the [Database Group Topology](../studio/database/settings/manage-database-group)
from the first server on this list that it successfully connected to. An exception is thrown if the client fails to connect with neither
of the servers specified on this list. The URLs from the Database Group Topology will supersede this initial URLs list for any future
access to that database.

* **Note**: Do not create a Document Store with URLs that point to servers outside of your cluster.

* **Note**: This list is not binding. You can always modify your cluster later dynamically, add new nodes or remove existing ones as
necessary. Learn more in [Cluster View Operations](../studio/cluster/cluster-view#cluster-view-operations).

* **[Database](../client-api/setting-up-default-database)** (optional)
The default database which the Client will work against.
A different database can be specified when creating a [Session](../client-api/session/opening-a-session) if needed.

* **[Conventions](../client-api/configuration/conventions)** (optional)
Customize the Client behavior with a variety of options, overriding the default settings.

* **[Certificate](../client-api/setting-up-authentication-and-authorization)** (optional)
X.509 certificate used to authenticate the client to the RavenDB server

After setting the above configurations as necessary, call `.Initialize()` to begin using the Document Store.

{WARNING: }
The Document Store is immutable - all above configuration are frozen upon calling .Initialize().
Create a new document store object if you need different default configuration values.
{WARNING/}

{PANEL/}

{PANEL: Creating a Document Store - Example}

This example demonstrates how to implement the singleton pattern in the initialization of a Document Store, as well as how to set initial
default configurations.

{CODE document_store_holder@ClientApi\CreatingDocumentStore.cs /}

{PANEL/}

## Related Articles

### Client API

- [What is a Document Store](../client-api/what-is-a-document-store)
- [Setting up Default Database](../client-api/setting-up-default-database)
- [Setting up Authentication and Authorization](../client-api/setting-up-authentication-and-authorization)
- [Conventions Overview](../client-api/configuration/conventions)
- [What is a Session and How Does it Work](../client-api/session/what-is-a-session-and-how-does-it-work)

Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
namespace Raven.Documentation.Samples.ClientApi
{
using System;
using System.Security.Cryptography.X509Certificates;
using Client.Documents;

public class CreatingDocumentStore
{

#region document_store_holder
// The `DocumentStoreHolder` class holds a single Document Store instance.
public class DocumentStoreHolder
{
// Use Lazy<IDocumentStore> to initialize the document store lazily.
// This ensures that it is created only once - when first accessing the public `Store` property.
private static Lazy<IDocumentStore> store = new Lazy<IDocumentStore>(CreateStore);

public static IDocumentStore Store => store.Value;

private static IDocumentStore CreateStore()
{
IDocumentStore store = new DocumentStore()
{
// Define the cluster node URLs (required)
Urls = new[] { "http://your_RavenDB_cluster_node",
/*some additional nodes of this cluster*/ },

// Set conventions as necessary (optional)
Conventions =
{
MaxNumberOfRequestsPerSession = 10,
UseOptimisticConcurrency = true
},

// Define a default database (optional)
Database = "your_database_name",

// Define a client certificate (optional)
Certificate = new X509Certificate2("C:\\path_to_your_pfx_file\\cert.pfx"),

// Initialize the Document Store
}.Initialize();

return store;
}
}
#endregion
}

public class CertificateCleanup
{
// The `DocumentStoreHolder` class holds a single Document Store instance.
public class DocumentStoreHolder
{
// Use Lazy<IDocumentStore> to initialize the document store lazily.
// This ensures that it is created only once - when first accessing the public `Store` property.
private static Lazy<IDocumentStore> store = new Lazy<IDocumentStore>(CreateStore);

public static IDocumentStore Store => store.Value;

private static IDocumentStore CreateStore()
{
IDocumentStore store = new DocumentStore()
{
// Define the cluster node URLs (required)
Urls = new[] { "http://your_RavenDB_cluster_node",
/*some additional nodes of this cluster*/ },

// Set conventions as necessary (optional)
Conventions =
{
MaxNumberOfRequestsPerSession = 10,
UseOptimisticConcurrency = true
},

// Define a default database (optional)
Database = "your_database_name",

// Define a client certificate (optional)
Certificate = new X509Certificate2("C:\\path_to_your_pfx_file\\cert.pfx"),

// Initialize the Document Store
}.Initialize();

return store;
}
}
}
}

0 comments on commit df93a0f

Please sign in to comment.