Lazyguy.Data.SqlSugar.StackExchange 1.0.2

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Lazyguy.Data.SqlSugar.StackExchange --version 1.0.2
                    
NuGet\Install-Package Lazyguy.Data.SqlSugar.StackExchange -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Lazyguy.Data.SqlSugar.StackExchange" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Lazyguy.Data.SqlSugar.StackExchange" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Lazyguy.Data.SqlSugar.StackExchange" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Lazyguy.Data.SqlSugar.StackExchange --version 1.0.2
                    
#r "nuget: Lazyguy.Data.SqlSugar.StackExchange, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Lazyguy.Data.SqlSugar.StackExchange@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Lazyguy.Data.SqlSugar.StackExchange&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Lazyguy.Data.SqlSugar.StackExchange&version=1.0.2
                    
Install as a Cake Tool

Lazyguy.AspNetCore.Swagger


进击的码农:693137603(刚建的空群)


// 有默认值的均可不设置
{
  "LgSwaggerOptions": {
    "Title": "Net6项目Api文档",
    "UseToken": true, // Default true
    "RoutePrefix": "", // Default string.Empty
    "DisableMiniProfiler": false, // Default false
    "UseApiVersion": false, // Default false //TODO:感觉这里控制是否多版本不合适
    "Versions": // Default []
    [
      {
        "Version": "1.0",
        "Description": "版本1.0"
      },
      {
        "Version": "1.1",
        "Description": "版本1.1"
      }
    ]
  }
}


var builder = WebApplication.CreateBuilder(args);

builder.Services.AddLgSwagger(builder.Configuration); // 添加

var app = builder.Build();

app.UseLgSwagger(); // 添加


Lazyguy.Core

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddLgServices() // 服务注册:默认扫描所有程序集
public interface ITestService 
{
}
public class TestService : ITestService, ITransient 
{ 
}

Lazyguy.AspNetCore.Jwt

{
    "LgJwtOptions": {
        "Secret": "01234567890123456789",
        "Issuer": "wosperry.com",
        "Audience": "wosperry.com",
        "ExpireMinutes": 1
    },
}
builder.Services.AddLgJwt(builder.Configuration); // 注入 IJwtService 使用

Lazyguy.Data.SqlSugar

{
    "LgSqlSugarOptions": {
        "ConnectionString": "server=192.168.124.220;port=3306;userid=root;password=Aa123456.;database=sqlsugar_test;Charset=utf8;AllowLoadLocalInfile=true;",
        "DbType": 0,
    },
    /*
        连接字符串 https://www.donet5.com/home/Doc?typeId=1229
        0-Mysql: server=localhost;Database=SqlSugar4xTest;Uid=root;Pwd=haosql;
        1-SqlServer: server=.;uid=sa;pwd=haosql;database=SQLSUGAR4XTEST
        2-Sqlite: Data Source=xxx.db
        3-Oracle: server=.;uid=sa;pwd=haosql;database=SQLSUGAR4XTEST
        4-PostgreSQL: PORT=5432;DATABASE=SqlSugar4xTest;HOST=localhost;PASSWORD=haosql;USER ID=postgres
        5-Dm: Server=localhost; User Id=SYSDBA; PWD=SYSDBA;DATABASE=新DB
        5-Dm: PORT=5236;DATABASE=DAMENG;HOST=localhost;PASSWORD=SYSDBA;USER ID=SYSDBA
        6-Kdbndp: Server=127.0.0.1;Port=54321;UID=SYSTEM;PWD=system;database=SQLSUGAR4XTEST1
        7-Oscar: PORT=2003;DATABASE=osrdb;HOST=localhost;PASSWORD=szoscar55;USER ID=SYSDBA
    */
}
builder.Services.AddLgSqlSugar(builder.Configuration) // 配置了这个后,注入IRepository使用


// CodeFirst迁移数据库使用
// 实现了IEntity接口的实体类,才执行Migrate
app.UseLgSqlSugarMigrator();

实体:


// 必须要继承自IEntity
// 用法参考EFCore
// 必须有 Table Key Column,后面可能会加入默认值
[Table("t_book")]
public class Book:IEntity
{
    [Key]
    [Column("book_id")]
    [Comment("主键")]
    public int Id { get; set; }
    [Column("book_name")]
    [Comment("名字")]
    public string? Name { get; set; }
}

通用仓储:


// 注入 IRepository<Book> 即可操作数据,Book必须实现 IEntity


Lazyguy.Data.SqlSugar.StackExchange

{
    "LgSqlSugarOptions": {
        "ConnectionString": "server=192.168.124.220;port=3306;userid=root;password=Aa123456.;database=sqlsugar_test;Charset=utf8;AllowLoadLocalInfile=true;",
        "DbType": 0,
        "RedisConn":"192.168.124.220:6379,password=Aa123456."
    },
    /*
        连接字符串 https://www.donet5.com/home/Doc?typeId=1229
        0-Mysql: server=localhost;Database=SqlSugar4xTest;Uid=root;Pwd=haosql;
        1-SqlServer: server=.;uid=sa;pwd=haosql;database=SQLSUGAR4XTEST
        2-Sqlite: Data Source=xxx.db
        3-Oracle: server=.;uid=sa;pwd=haosql;database=SQLSUGAR4XTEST
        4-PostgreSQL: PORT=5432;DATABASE=SqlSugar4xTest;HOST=localhost;PASSWORD=haosql;USER ID=postgres
        5-Dm: Server=localhost; User Id=SYSDBA; PWD=SYSDBA;DATABASE=新DB
        5-Dm: PORT=5236;DATABASE=DAMENG;HOST=localhost;PASSWORD=SYSDBA;USER ID=SYSDBA
        6-Kdbndp: Server=127.0.0.1;Port=54321;UID=SYSTEM;PWD=system;database=SQLSUGAR4XTEST1
        7-Oscar: PORT=2003;DATABASE=osrdb;HOST=localhost;PASSWORD=szoscar55;USER ID=SYSDBA
    */
}
builder.Services.AddLgSqlSugarWithRedisCache(builder.Configuration) // 配置了这个后,注入IRepository使用


// CodeFirst迁移数据库使用
// 实现了IEntity接口的实体类,才执行Migrate
app.UseLgSqlSugarMigrator();

实体:


// 必须要继承自IEntity
// 用法参考EFCore
// 必须有 Table Key Column,后面可能会加入默认值
[Table("t_book")]
public class Book:IEntity
{
    [Key]
    [Column("book_id")]
    [Comment("主键")]
    public int Id { get; set; }
    [Column("book_name")]
    [Comment("名字")]
    public string? Name { get; set; }
}

通用仓储:


// 注入 IRepositoryWithCache<Book> 即可操作数据,Book必须实现 IEntity

Lazyguy.Tool.QuartzJobs


// 确保入口调用了以下
builder.Services.AddLgServices();

// 在其他服务里注入 ILgQuartzJobService ,即可

示例:

Programe.cs

var builder = WebApplication.CreateBuilder(args);

builder.Services
    .AddLgServices()
    .AddLgSwagger(builder.Configuration)
    .AddControllers(); // 添加控制器

var app = builder.Build();
app.UseLgSwagger();
app.MapControllers();
app.Run();

Controller

[ApiController]
[Route("test")]
public class TestController : ControllerBase
{
    private readonly ILgQuartzJobService _quartzJobService;

    public TestController(ILgQuartzJobService quartzJobService)
    {
        _quartzJobService=quartzJobService;
    }

    [HttpPost("start")]
    public async Task Start()
    {
        // Start方法还有其他几个参数
        await _quartzJobService.StartAsync<MyJob>("test_job");
        
        // 如果手动指定前两个参数,则关闭时参数一定要与开启时一致,否则无法找到Job关闭
        // 开启:await _quartzService.StartAsync<MyJob>("test_job", "test", TimeSpan.FromSeconds(5));
        // 关闭:await _quartzService.StopAsync<MyJob>("test_job", "test");
    }

    [HttpPost("stop")]
    public async Task StopAsync()
    {
        // 提供第一个参数时,会找到相应的trigger并关闭任务
        // 不提供参数时,会找到MyJob的所有任务关闭全部
        await _quartzJobService.StopAsync<MyJob>();
    }
}

Job

// 此特性指定默认执行周期,依次是时分秒,如果不提供则默认十分钟一次
[DefaultInterval(0, 0, 1)]
public class MyJob : IJob, ITransient // ITransient非必须,如果不添加则需要手动添加MyJob到DI容器
{
    // 如果需要注入服务,则需要将MyJob添加到DI容器里,不然就走无参数构造对象不支持构造函数注入
    // 这里ITransient是程序扫描注册到DI容器,类似接口还有 ISingleTon IScoped
    private readonly ITestService _testService;
    public MyJob(ITestService testService)
    {
        _testService=testService;
    }

    public async Task Execute(IJobExecutionContext context)
    {
        Console.WriteLine($"【任务执行:{DateTime.Now:HH:mm:ss}】  {_testService?.Get()}");
        await Task.Delay(20);
    }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0-pre4 277 1/8/2022
1.1.0-pre3 269 1/8/2022
1.1.0-pre2 262 1/7/2022
1.1.0-pre1 257 1/7/2022
1.0.2 781 1/6/2022
1.0.1 813 1/6/2022