34 lines
1.2 KiB
C#
34 lines
1.2 KiB
C#
using MessengerApi.Configuration.Model.Persistence;
|
|
using MessengerApi.Configuration.Model.Persistence.Base;
|
|
using MessengerApi.Contracts.Factories;
|
|
using MessengerApi.Db;
|
|
using MessengerApi.Db.Npg;
|
|
using MessengerApi.Db.Sql;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace MessengerApi.Factories
|
|
{
|
|
public class DbContextFactory : IDbContextFactory, IDbContextFactory<MessengerDbContext>
|
|
{
|
|
private readonly PersistenceConfiguration configuration;
|
|
|
|
public DbContextFactory(PersistenceConfiguration configuration)
|
|
{
|
|
this.configuration = configuration;
|
|
}
|
|
|
|
public MessengerDbContext CreateDbContext()
|
|
{
|
|
if (this.configuration.PersistenceType == Configuration.Enums.PersistenceTypes.Sql)
|
|
{
|
|
return new MessengerSqlDbContext((configuration as SqlPersistenceConfiguration).ConnectionString);
|
|
}
|
|
else if (this.configuration.PersistenceType == Configuration.Enums.PersistenceTypes.PostgreSql)
|
|
{
|
|
return new MessengerNpgDbContext((configuration as NpgPersistenceConfiguration).ConnectionString);
|
|
}
|
|
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
} |