dotnet-db-context/PoweredSoft.DbContext.EntityFramework/EntityFrameworkDbContextServiceFactory.cs
2021-09-20 10:21:48 -04:00

30 lines
904 B
C#

using PoweredSoft.DbContext.Core;
using System;
using System.Collections.Generic;
using System.Text;
namespace PoweredSoft.DbContext.EntityFramework
{
public class EntityFrameworkDbContextServiceFactory : IContextServiceFactory
{
private readonly IServiceProvider serviceProvider;
public EntityFrameworkDbContextServiceFactory(IServiceProvider serviceProvider)
{
this.serviceProvider = serviceProvider;
}
public bool CanService(Type contextType)
{
return typeof(System.Data.Entity.DbContext).IsAssignableFrom(contextType);
}
public IDbContextService Create(Type contextType)
{
var service = serviceProvider.GetService(contextType) as System.Data.Entity.DbContext;
var contextService = new DbContextService(service);
return contextService;
}
}
}