Skip to content

Commit

Permalink
add unitofworkmanger<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
luoyunchong committed Mar 12, 2024
1 parent 0ca6d1f commit ca37505
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/IGeekFan.FreeKit.Extras/FreeSql/FreeSqlExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static class FreeSqlExtension
/// </summary>
/// <param name="this"></param>
/// <param name="configuration"></param>
/// <param name="prefix"></param>
/// <returns></returns>
public static FreeSqlBuilder UseConnectionString(this FreeSqlBuilder @this, IConfiguration configuration, string prefix = "ConnectionStrings")
{
Expand Down
18 changes: 18 additions & 0 deletions src/IGeekFan.FreeKit.Extras/FreeSql/UnitOfWorkManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using FreeSql;

namespace IGeekFan.FreeKit.Extras.FreeSql;

/// <summary>
/// 支持泛型仓储的工作单元管理器
/// </summary>
/// <typeparam name="T"></typeparam>
public class UnitOfWorkManager<T> : UnitOfWorkManager where T : class
{
/// <summary>
///
/// </summary>
/// <param name="fsql"></param>
public UnitOfWorkManager(IFreeSql<T> fsql) : base(fsql)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,25 @@ namespace Microsoft.Extensions.DependencyInjection;

public static class ServiceCollectionExtensions
{

public static IServiceCollection AddUnitOfWorkManager<T>(this IServiceCollection serviceCollection) where T : class
{
serviceCollection.AddTransient<UnitOfWorkActionFilter>();
serviceCollection.TryAddScoped<UnitOfWorkManager<T>>();
return serviceCollection;
}

public static IServiceCollection AddUnitOfWorkManager(this IServiceCollection serviceCollection)
{
serviceCollection.AddTransient<UnitOfWorkActionFilter>();
serviceCollection.TryAddScoped<UnitOfWorkManager>();

return serviceCollection;
}

/// <summary>
/// 统一配置服务,简化内部多个配置细节
/// </summary>
/// <param name="services"></param>
/// <param name="typeUserkey">用户表类型,默认为guid</param>
/// <returns></returns>
public static IServiceCollection AddFreeKitCore(this IServiceCollection services, Type? typeUserkey = null)
{
//(controller unitofwork fitler
Expand All @@ -22,16 +35,12 @@ public static IServiceCollection AddFreeKitCore(this IServiceCollection services
//审计仓储
//复合主键仓储)
services.AddHttpContextAccessor();

services
.AddTransient<UnitOfWorkActionFilter>()
.AddCurrentUser()
services.AddCurrentUser()
.AddCurrentUserAccessor()
.AddAuditRepostiory(typeUserkey)
.AddCompositeRepostiory();

services.AddDefaultRepository();
services.TryAddScoped<UnitOfWorkManager>();

return services;
}
Expand Down Expand Up @@ -76,11 +85,11 @@ public static IServiceCollection AddAuditRepostiory(this IServiceCollection serv
{
throw new NotSupportedException("用户ID仅支持Guid/long/int类型");
}

return services;
}



/// <summary>
/// 批量注入 IBaseRepository
/// </summary>
Expand Down

0 comments on commit ca37505

Please sign in to comment.