mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-28 13:42:51 +08:00

- 增加 行级锁功能,适用修改实体; - 增加 FreeSql.Repository 默认依赖注入的方式,同时保留原有 Autofac; - 优化 FreeSql.Repository Insert 逻辑,参考了 FreeSql.DbContext; - 优化 FreeSql.IUpdate 参照 IInsert 对大批量更新,拆分执行; - 修复 FreeSql.IInsert ClearData 重复利用的 bug(使用 IgnoreColumns 进行大批量插入时会发生);
39 lines
1.4 KiB
C#
39 lines
1.4 KiB
C#
using FreeSql;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Concurrent;
|
|
using System.Linq.Expressions;
|
|
using System.Reflection;
|
|
using System.Linq;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace FreeSql {
|
|
public static class FreeSqlRepositoryDependencyInjection {
|
|
|
|
public static IServiceCollection AddFreeRepository(this IServiceCollection services, Action<FluentDataFilter> globalDataFilter = null, params Assembly[] assemblies) {
|
|
|
|
DataFilterUtil._globalDataFilter = globalDataFilter;
|
|
|
|
services.AddScoped(typeof(IReadOnlyRepository<>), typeof(GuidRepository<>));
|
|
services.AddScoped(typeof(IBasicRepository<>), typeof(GuidRepository<>));
|
|
services.AddScoped(typeof(BaseRepository<>), typeof(GuidRepository<>));
|
|
services.AddScoped(typeof(GuidRepository<>));
|
|
|
|
services.AddScoped(typeof(IReadOnlyRepository<,>), typeof(DefaultRepository<,>));
|
|
services.AddScoped(typeof(IBasicRepository<,>), typeof(DefaultRepository<,>));
|
|
services.AddScoped(typeof(BaseRepository<,>), typeof(DefaultRepository<,>));
|
|
services.AddScoped(typeof(DefaultRepository<,>));
|
|
|
|
if (assemblies?.Any() == true) {
|
|
foreach(var asse in assemblies) {
|
|
foreach (var repos in asse.GetTypes().Where(a => a.IsAbstract == false && typeof(IRepository).IsAssignableFrom(a))) {
|
|
|
|
services.AddScoped(repos);
|
|
}
|
|
}
|
|
}
|
|
|
|
return services;
|
|
}
|
|
}
|
|
} |