forked from elsa-workflows/elsa-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added an option to allow the user to opt-in for LINQ3 provider that actually causes regressions. See elsa-workflows#4000
- Loading branch information
1 parent
047c51d
commit 303e8b9
Showing
9 changed files
with
54 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/persistence/Elsa.Persistence.MongoDb/Services/ElsaMongoDbDriverHelpers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Elsa.Persistence.MongoDb.Options; | ||
using MongoDB.Driver; | ||
using System; | ||
using System.Collections.Concurrent; | ||
|
||
namespace Elsa.Persistence.MongoDb.Services | ||
{ | ||
public static class ElsaMongoDbDriverHelpers | ||
{ | ||
/// <summary> | ||
/// Avoid creating too much instances for MongoClient. | ||
/// </summary> | ||
private static readonly ConcurrentDictionary<string, MongoClient> _clients = new(); | ||
|
||
public static MongoClient CreateClient(ElsaMongoDbOptions options) | ||
{ | ||
if (string.IsNullOrEmpty(options.ConnectionString)) throw new ArgumentException("Connection string is required.", nameof(options.ConnectionString)); | ||
if (!_clients.TryGetValue(options.ConnectionString, out MongoClient client)) | ||
{ | ||
var connectionString = options.ConnectionString; | ||
var clientSettings = MongoClientSettings.FromConnectionString(connectionString); | ||
if (options.UseNewLinq3Provider == false) | ||
{ | ||
clientSettings.LinqProvider = MongoDB.Driver.Linq.LinqProvider.V2; | ||
} | ||
client = new MongoClient(clientSettings); | ||
_clients[options.ConnectionString] = client; | ||
} | ||
|
||
return client; | ||
} | ||
} | ||
} |