Initial commit carried over from private repo. This is V2.
This commit is contained in:
34
code/MessengerApi/Factories/DbContextFactory.cs
Normal file
34
code/MessengerApi/Factories/DbContextFactory.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using MessengerApi.Configuration.Model;
|
||||
using MessengerApi.Configuration.Model.Persistence;
|
||||
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 MessengerConfiguration configuration;
|
||||
|
||||
public DbContextFactory(MessengerConfiguration configuration)
|
||||
{
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
public MessengerDbContext CreateDbContext()
|
||||
{
|
||||
if (this.configuration.PersistenceConfiguration.PersistenceType == Configuration.Enums.PersistenceTypes.Sql)
|
||||
{
|
||||
return new MessengerSqlDbContext((configuration.PersistenceConfiguration as SqlPersistenceConfiguration).ConnectionString);
|
||||
}
|
||||
else if (this.configuration.PersistenceConfiguration.PersistenceType == Configuration.Enums.PersistenceTypes.PostgreSql)
|
||||
{
|
||||
return new MessengerNpgDbContext((configuration.PersistenceConfiguration as NpgPersistenceConfiguration).ConnectionString);
|
||||
}
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user