Skip to content

Commit 9ff4b41

Browse files
committed
feat(efcore): 调整IServiceCollection.AddOsharpDbContext<TDbContext>()的执行位置 #225
1 parent bd705aa commit 9ff4b41

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/OSharp.EntityFrameworkCore/EntityFrameworkCorePackBase.cs

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ public abstract class EntityFrameworkCorePackBase : OsharpPack
5353
/// <returns></returns>
5454
public override IServiceCollection AddServices(IServiceCollection services)
5555
{
56-
services.AddOsharpDbContext<DefaultDbContext>();
5756
services.TryAddScoped<IAuditEntityProvider, AuditEntityProvider>();
5857
services.TryAddScoped(typeof(IRepository<,>), typeof(Repository<,>));
5958
services.TryAddScoped<IUnitOfWork, UnitOfWork>();

src/OSharp.EntityFrameworkCore/MigrationPackBase.cs

+11
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ public abstract class MigrationPackBase<TDbContext> : OsharpPack
3939
/// </summary>
4040
protected abstract DatabaseType DatabaseType { get; }
4141

42+
/// <summary>
43+
/// 将模块服务添加到依赖注入服务容器中
44+
/// </summary>
45+
/// <param name="services">依赖注入服务容器</param>
46+
/// <returns></returns>
47+
public override IServiceCollection AddServices(IServiceCollection services)
48+
{
49+
services.AddOsharpDbContext<TDbContext>();
50+
return services;
51+
}
52+
4253
/// <summary>
4354
/// 应用模块服务
4455
/// </summary>

src/OSharp.EntityFrameworkCore/ServiceExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static class ServiceExtensions
3939
/// <param name="services">依赖注入服务集合</param>
4040
/// <param name="optionsAction">数据库选项创建配置,将在内置配置后运行</param>
4141
/// <returns>依赖注入服务集合</returns>
42-
public static IServiceCollection AddOsharpDbContext<TDbContext>(this IServiceCollection services, Action<IServiceProvider, DbContextOptionsBuilder> optionsAction = null) where TDbContext : DbContextBase
42+
public static IServiceCollection AddOsharpDbContext<TDbContext>(this IServiceCollection services, Action<IServiceProvider, DbContextOptionsBuilder> optionsAction = null) where TDbContext : DbContext
4343
{
4444
services = services.AddDbContext<TDbContext>((provider, builder) =>
4545
{

0 commit comments

Comments
 (0)