mirror of
https://github.com/opengram-server/opengram.git
synced 2026-09-11 21:14:14 +03:00
Initial commit
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
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";
|
||||
}
|
||||
Reference in New Issue
Block a user