-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathMongoDbStorageSettings.cs
More file actions
87 lines (80 loc) · 4.26 KB
/
MongoDbStorageSettings.cs
File metadata and controls
87 lines (80 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using Microsoft.Extensions.Configuration;
namespace Bot.Builder.Community.Storage.MongoDB
{
public class MongoDbStorageSettings
{
public Type[] AllowedTypes { get; private set; }
public MongoDbStorageOptions Options { get; private set; }
/// <summary>
/// Registers the specified types for MongoDB storage.
/// </summary>
/// <param name="types">An array of <see cref="Type"/> objects to be registered for storage.</param>
/// <returns>The current <see cref="MongoDbStorageSettings"/> instance, allowing method calls to be chained.</returns>
/// <remarks>
/// This method sets the <see cref="AllowedTypes"/> property with the provided types. It is useful for configuring the MongoDB storage settings with the desired types that need to be stored in the database.
/// </remarks>
public MongoDbStorageSettings RegisterTypes(params Type[] types)
{
AllowedTypes = types;
return this;
}
/// <summary>
/// Configures the <see cref="MongoDbStorageOptions"/> using the provided <see cref="IConfigurationSection"/>.
/// </summary>
/// <param name="configuration">The <see cref="IConfigurationSection"/> to bind the options to.</param>
/// <returns>The current <see cref="MongoDbStorageSettings"/> instance, allowing method calls to be chained.</returns>
/// <remarks>
/// This method creates a new instance of <see cref="MongoDbStorageOptions"/> and binds the provided configuration section to it. The resulting options are then used to configure the MongoDB storage settings.
/// </remarks>
/// <example>
/// ...
/// "ConnectionString": "...",
/// "DatabaseName": "...",
/// "CollectionName": "...",
/// ...
/// </example>
public MongoDbStorageSettings ConfigureOptions(IConfigurationSection configuration)
{
Options = new MongoDbStorageOptions();
configuration.Bind(Options);
return this;
}
/// <summary>
/// Configures the <see cref="MongoDbStorageOptions"/> using the provided <see cref="MongoDbStorageOptions"/> instance.
/// </summary>
/// <param name="options">The <see cref="MongoDbStorageOptions"/> instance to use for configuration.</param>
/// <returns>The current <see cref="MongoDbStorageSettings"/> instance, allowing method calls to be chained.</returns>
/// <remarks>
/// This method sets the <see cref="Options"/> property with the provided <see cref="MongoDbStorageOptions"/> instance. It is useful for configuring the MongoDB storage settings using a preconfigured options object.
/// </remarks>
public MongoDbStorageSettings ConfigureOptions(MongoDbStorageOptions options)
{
Options = options;
return this;
}
/// <summary>
/// Configures the <see cref="MongoDbStorageOptions"/> using the provided connection string, database name, and optionally, collection name.
/// </summary>
/// <param name="connectionString">The connection string for the MongoDB instance.</param>
/// <param name="databaseName">The name of the database to be used for storage.</param>
/// <param name="collectionName">The optional name of the collection to be used for storage (default is null).</param>
/// <returns>The current <see cref="MongoDbStorageSettings"/> instance, allowing method calls to be chained.</returns>
/// <remarks>
/// This method creates a new instance of <see cref="MongoDbStorageOptions"/> and sets the provided connection string, database name, and collection name (if provided). The resulting options are then used to configure the MongoDB storage settings.
/// </remarks>
public MongoDbStorageSettings ConfigureOptions(
string connectionString,
string databaseName,
string collectionName = null)
{
Options = new MongoDbStorageOptions
{
ConnectionString = connectionString,
DatabaseName = databaseName,
CollectionName = collectionName
};
return this;
}
}
}