diff --git a/src/AbpDesk/AbpDesk.EntityFrameworkCore/AbpDesk/EntityFrameworkCore/AbpDeskEntityFrameworkCoreModule.cs b/src/AbpDesk/AbpDesk.EntityFrameworkCore/AbpDesk/EntityFrameworkCore/AbpDeskEntityFrameworkCoreModule.cs index 7bb6f00b3f..7b5b7b9f96 100644 --- a/src/AbpDesk/AbpDesk.EntityFrameworkCore/AbpDesk/EntityFrameworkCore/AbpDeskEntityFrameworkCoreModule.cs +++ b/src/AbpDesk/AbpDesk.EntityFrameworkCore/AbpDesk/EntityFrameworkCore/AbpDeskEntityFrameworkCoreModule.cs @@ -1,9 +1,10 @@ using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.EntityFrameworkCore; using Volo.Abp.Modularity; namespace AbpDesk.EntityFrameworkCore { - [DependsOn(typeof(AbpDeskDomainModule))] + [DependsOn(typeof(AbpDeskDomainModule), typeof(AbpEntityFrameworkCoreModule))] public class AbpDeskEntityFrameworkCoreModule : AbpModule { public override void ConfigureServices(IServiceCollection services) diff --git a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreModule.cs b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreModule.cs new file mode 100644 index 0000000000..437a3204a6 --- /dev/null +++ b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreModule.cs @@ -0,0 +1,16 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; +using Volo.Abp.Modularity; +using Volo.Abp.Repositories.EntityFrameworkCore; + +namespace Volo.Abp.EntityFrameworkCore +{ + public class AbpEntityFrameworkCoreModule : AbpModule + { + public override void ConfigureServices(IServiceCollection services) + { + //TODO: This will be changed! + services.TryAddTransient(typeof(IDbContextProvider<>), typeof(DefaultDbContextProvider<>)); + } + } +} diff --git a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/DefaultDbContextProvider.cs b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/DefaultDbContextProvider.cs new file mode 100644 index 0000000000..30654e264c --- /dev/null +++ b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/DefaultDbContextProvider.cs @@ -0,0 +1,20 @@ +using Volo.Abp.EntityFrameworkCore; + +namespace Volo.Abp.Repositories.EntityFrameworkCore +{ + public class DefaultDbContextProvider : IDbContextProvider + where TDbContext : AbpDbContext + { + private readonly TDbContext _dbContext; + + public DefaultDbContextProvider(TDbContext dbContext) + { + _dbContext = dbContext; + } + + public TDbContext GetDbContext() + { + return _dbContext; + } + } +} \ No newline at end of file diff --git a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/EfCoreRepository.cs b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/EfCoreRepository.cs index 04c342defa..90e683f0b5 100644 --- a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/EfCoreRepository.cs +++ b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/EfCoreRepository.cs @@ -12,15 +12,17 @@ namespace Volo.Abp.Repositories.EntityFrameworkCore where TDbContext : AbpDbContext where TEntity : class, IEntity { - public virtual TDbContext DbContext { get; } - + public virtual TDbContext DbContext => _dbContextProvider.GetDbContext(); + public virtual DbSet DbSet => DbContext.Set(); DbContext IEfCoreRepository.DbContext => DbContext; - public EfCoreRepository(TDbContext dbContext) + private readonly IDbContextProvider _dbContextProvider; + + public EfCoreRepository(IDbContextProvider dbContextProvider) { - DbContext = dbContext; + _dbContextProvider = dbContextProvider; } protected override IQueryable GetQueryable() diff --git a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/IDbContextProvider.cs b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/IDbContextProvider.cs new file mode 100644 index 0000000000..f28ad52501 --- /dev/null +++ b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/IDbContextProvider.cs @@ -0,0 +1,10 @@ +using Volo.Abp.EntityFrameworkCore; + +namespace Volo.Abp.Repositories.EntityFrameworkCore +{ + public interface IDbContextProvider + where TDbContext : AbpDbContext + { + TDbContext GetDbContext(); + } +} \ No newline at end of file diff --git a/src/Volo.Abp/Volo/Abp/Data/IConnectionInfoResolver.cs b/src/Volo.Abp/Volo/Abp/Data/IConnectionInfoResolver.cs new file mode 100644 index 0000000000..3a7ce31aab --- /dev/null +++ b/src/Volo.Abp/Volo/Abp/Data/IConnectionInfoResolver.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Volo.Abp.Data +{ + public interface IConnectionInfoResolver + { + ConnectionInfo Resolve(); + } + + public class ConnectionInfo + { + public string ConnectionString { get; set; } + } +}