mirror of
https://github.com/opengram-server/opengram.git
synced 2026-09-08 19:44:12 +03:00
26 lines
881 B
C#
26 lines
881 B
C#
using Microsoft.Extensions.Configuration;
|
|
using MongoDB.Driver;
|
|
|
|
namespace MyTelegram.EventFlow.MongoDB;
|
|
|
|
public class
|
|
DefaultEventStoreMongoDbContext(IConfiguration configuration) : IMongoDbContext
|
|
{
|
|
private IMongoDatabase? _database;
|
|
|
|
public IMongoDatabase GetDatabase()
|
|
{
|
|
if (_database == null)
|
|
{
|
|
var connectionString = configuration.GetConnectionString(GetConnectionStringName());
|
|
var databaseName = configuration.GetValue<string>(GetKeyOfDatabaseNameInConfiguration());
|
|
var client = new MongoClient(connectionString);
|
|
_database = client.GetDatabase(databaseName);
|
|
}
|
|
|
|
return _database;
|
|
}
|
|
|
|
protected virtual string GetConnectionStringName() => "Default";
|
|
protected virtual string GetKeyOfDatabaseNameInConfiguration() => "App:DatabaseName";
|
|
} |