37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
using System;
|
|
using LCU.API.Internal.DocumentLib.Configurations;
|
|
using LCU.API.Internal.DocumentLib.Containers;
|
|
using LCU.API.Internal.DocumentLib.Repositories;
|
|
using MongoDB.Driver;
|
|
|
|
namespace LCU.API.Internal.DocumentLib.Utilities;
|
|
|
|
public class MongoCollectionFactory : IMongoCollectionFactory
|
|
{
|
|
private readonly IDataClient _mongoDataClient;
|
|
private readonly DatabaseConfiguration _config;
|
|
|
|
public MongoCollectionFactory(IDataClient mongoDataClient, DatabaseConfiguration config)
|
|
{
|
|
_mongoDataClient = mongoDataClient;
|
|
_config = config;
|
|
}
|
|
|
|
public IMongoCollection<T> GetCollection<T>()
|
|
{
|
|
return _mongoDataClient
|
|
.GetClient()
|
|
.GetDatabase(_config.DatabaseName)
|
|
.GetCollection<T>(CollectionNameFor<T>());
|
|
}
|
|
|
|
private string CollectionNameFor<T>()
|
|
{
|
|
return typeof(T) switch
|
|
{
|
|
var t when t == typeof(DocumentInformation) => _config.DocumentContainerName,
|
|
var t when t == typeof(DocumentAudit) => _config.AuditContainerName,
|
|
_ => throw new NotImplementedException()
|
|
};
|
|
}
|
|
} |