Giter Site home page Giter Site logo

luoyunchong / freekit Goto Github PK

View Code? Open in Web Editor NEW
22.0 3.0 7.0 980 KB

FreeKit为.NET Core提供了更多的扩展实现,包括FreeSql Repository 跨方法AOP事务、ASP.NET Core Identity的FreeSql存储、本地化的FreeSql实现

Home Page: https://igeekfan.cn

License: MIT License

C# 97.69% Batchfile 0.04% PowerShell 2.27%
aspnetcore aspnetcoreidentity email freesql modularity ientity healthchecks localization

freekit's Introduction

FreeKit

.NET logoYEARS

Freekit 为.NET Core提供了更多的扩展实现

.NET IDE Rider GitHub license

英文 | 中文

Nuget Packages

Package name Version Downloads
IGeekFan.AspNetCore.Identity.FreeSql NuGet downloads
IGeekFan.FreeKit NuGet downloads
IGeekFan.FreeKit.Extras NuGet downloads
IGeekFan.FreeKit.Modularity NuGet downloads
IGeekFan.FreeKit.Email NuGet downloads
IGeekFan.Localization.FreeSql NuGet downloads
IGeekFan.Extensions.Diagnostics.HealthChecks.FreeSql NuGet downloads
IGeekFan.AspNetCore.DataProtection.FreeRedis NuGet downloads
IGeekFan.AspNetCore.DataProtection.FreeSql NuGet downloads

BaGet Packages

Package name Version
IGeekFan.AspNetCore.Identity.FreeSql BaGet
IGeekFan.FreeKit BaGet
IGeekFan.FreeKit.Extras BaGet
IGeekFan.FreeKit.Modularity BaGet
IGeekFan.FreeKit.Email BaGet
IGeekFan.Localization.FreeSql BaGet
IGeekFan.Extensions.Diagnostics.HealthChecks.FreeSql BaGet
IGeekFan.AspNetCore.DataProtection.FreeRedis BaGet
IGeekFan.AspNetCore.DataProtection.FreeSql BaGet

IGeekFan.AspNetCore.Identity.FreeSql

asp.net core 6identityfreesql实现

IGeekFan.FreeKit

  • AuditEntity 审计日志实体
  • Dependency 依赖注入接口
  • 查看IGeekFan.FreeKit文档

IGeekFan.FreeKit.Extras

  • FreeSql扩展+Autofac UnitOfWork
  • FreeSql+AuditEntity
  • Autofac+ITransientDependency+IScopedDependency+ISingletonDependency
  • CaseQuery
  • Security 登录人信息
  • 查看IGeekFan.FreeKit.Extras文档

IGeekFan.FreeKit.Email

IGeekFan.Localization.FreeSql

IGeekFan.FreeKit.Modularity

freekit's People

Contributors

luoyunchong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

freekit's Issues

FreeSql + DataProtection怎么使用?有文档和例子吗。

描述你希望的支持的新功能?
FreeSql + DataProtection怎么使用?有文档和例子吗。
项目用freeSql做orm。现在打算引入用Microsoft.AspNetCore.DataProtection。
由于多应用部署在docker上,密钥存储和共享就有点麻烦。
本地和注册表什么的就没戏,数据库的话不想引入EFCore,想直接使用FreeSql。目前是存储在redis中的。
你期望的 API 是怎样的?

AOP 给当前审计日志赋值

AOP审计日志赋值

安装包IGeekFan.FreeKit.Extras

dotnet add package IGeekFan.FreeKit.Extras

增加扩展

public static class CurrentUserExtensions
{
    public static Guid? FindUserId(this ICurrentUser currentUser)
    {
        return currentUser.FindUserIdToGuid();
    }
}

给FreeSql 的AOP AuditValue赋值

public static class ServiceCollectionExtensions
{
    public static void AuditValue(AuditValueEventArgs e, ICurrentUser? user)
    {
        if (e.AuditValueType == AuditValueType.Insert)
        {
            if (e.Column.CsName == "CreateUserId")
            {
                e.Value = user?.FindUserId();
            }
            if (e.Column.CsName == "CreateUserName")
            {
                e.Value = user?.UserName;
            }
            if (e.Column.CsName == "CreateTime")
            {
                e.Value = DateTime.Now;
            }
            if (e.Column.CsName == "TenantId")
            {
                e.Value = user?.TenantId;
            }
        }
        else if (e.AuditValueType == AuditValueType.Update)
        {
            if (e.Column.CsName == "UpdateUserId")
            {
                e.Value = user?.FindUserId();
            }
            if (e.Column.CsName == "UpdateUserName")
            {
                e.Value = user?.UserName;
            }
            if (e.Column.CsName == "UpdateTime")
            {
                e.Value = DateTime.Now;
            }
        }
    }

  public static IServiceCollection AddFreeSql(this IServiceCollection services, IConfiguration configuration)
  {
      services.AddCurrentUserAccessor();
      IFreeSql fsql = new FreeSqlBuilder()
                 .UseConnectionString(configuration)
                .UseNameConvert(NameConvertType.PascalCaseToUnderscoreWithLower)
                .UseAutoSyncStructure(true) //自动同步实体结构到数据库,FreeSql不会扫描程序集,只有CRUD时才会生成表。
                .UseMonitorCommand(cmd =>
                {
                    Trace.WriteLine(cmd.CommandText + ";");
                })
                .Build();
      var provider = services.BuildServiceProvider();
      var currentAccessor = provider.GetRequiredService<ICurrentUserAccessor>();
      
      fsql.GlobalFilter.ApplyOnly<ISoftDelete>("IsDeleted", a => a.IsDeleted == false);
      fsql.GlobalFilter.ApplyOnlyIf<ITenant>("TenantId", () => currentAccessor.CurrentUser?.TenantId != null, a => a.TenantId == currentAccessor.CurrentUser.TenantId);
      
      fsql.Aop.AuditValue += (s, e) =>
      {
                  AuditValue(e, currentAccessor.CurrentUser);
      };
      
      services.AddSingleton<IFreeSql>(fsql);
      services.AddFreeRepository();
      services.AddScoped<UnitOfWorkManager>();
      
      return services;
  }
}

引用服务

builder.Services.AddFreeSql(builder.Configuration);

中间件

//自定义中间件,给ICurrentUserAccessor中的CurrentUser赋值
app.UseCurrentUserAccessor();

appsettings.json配置

 "ConnectionStrings": {
    "DefaultDB": "4",
    "MySql": "Data Source=localhost;Port=3306;User ID=root;Password=root;Initial Catalog=freekit;Charset=utf8mb4;SslMode=none;Max pool size=1;Connection LifeTime=20",
    "SqlServer": "Data Source=.;User ID=sa;Password=123456;Integrated Security=True;Initial Catalog=LinCMS;Pooling=true;Min Pool Size=1",
    "PostgreSQL": "Host=localhost;Port=5432;Username=postgres;Password=123456; Database=lincms;Pooling=true;Minimum Pool Size=1",
    "Oracle": "user id=root;password=root; data source=//127.0.0.1:1521/ORCL;Pooling=true;Min Pool Size=1",
    "Sqlite": "Data Source=Identity.db"
  },

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.