using NetAdmin.AdmServer.Host.Filters;
using NetAdmin.Domain.Contexts;
using NetAdmin.Domain.DbMaps.Dependency.Fields;
using NetAdmin.Domain.Enums.Sys;
using NetAdmin.Host.Extensions;
namespace NetAdmin.AdmServer.Host.Extensions;
///
/// ServiceCollection 扩展方法
///
[SuppressSniffer]
public static class ServiceCollectionExtensions
{
///
/// 添加 FreeSql
///
public static IServiceCollection AddFreeSqlWithArgs(this IServiceCollection me)
{
return me.AddFreeSql( //
(Startup.Args.SyncStructure ? FreeSqlInitMethods.SyncStructure : FreeSqlInitMethods.None) |
(Startup.Args.InsertSeedData ? FreeSqlInitMethods.InsertSeedData : FreeSqlInitMethods.None), freeSql => {
// 数据权限过滤器
_ = freeSql.GlobalFilter.ApplyOnlyIf( //
Chars.FLG_FREE_SQL_GLOBAL_FILTER_DATA
, () => ContextUserInfo.Create()?.Roles.All(x => x.DataScope == DataScopes.Self) ?? false
, a => a.OwnerId == ContextUserInfo.Create().Id);
});
}
///
/// 添加 jwt 授权处理器
///
public static IServiceCollection AddJwt(this IServiceCollection me)
{
_ = me.AddJwt(enableGlobalAuthorize: true);
return me;
}
}