dotnet-data/PoweredSoft.Data.EntityFrameworkCore/DbContextFactoryProvider.cs
2018-11-23 01:22:05 -06:00

27 lines
814 B
C#

using PoweredSoft.Data.Core;
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.EntityFrameworkCore;
namespace PoweredSoft.Data.EntityFrameworkCore
{
public class DbContextFactoryProvider : IDbContextFactoryProvider
{
private readonly IServiceProvider serviceProvider;
public DbContextFactoryProvider(IServiceProvider serviceProvider)
{
this.serviceProvider = serviceProvider;
}
public IDbContextFactory GetContextFactory(Type contextType)
{
var dbContext = this.serviceProvider.GetRequiredService(contextType) as DbContext;
var dbContextFactory = new DbContextFactory(dbContext);
return dbContextFactory;
}
}
}