跳至主要內容

5.3 SQL追踪-SqlSugar

linguicheng...小于 1 分钟

简介

支持对ORM框架SqlSugar生成并执行的SQL语句进行跟踪与分析,以方便开发人员优化程序性能。

安装依赖包

示例5.3(点击查看完整示例代码open in new window)

dotnet add package Wing.Consul

dotnet add package Wing.APM.SqlSugar

dotnet add package Wing.Persistence

dotnet add package FreeSql.Provider.SqlServer

Program代码

using Wing;

var builder = WebApplication.CreateBuilder(args);

builder.Host.AddWing(builder => builder.AddConsul());

// Add services to the container.

builder.Services.AddControllers();

builder.Services.AddWing()
            .AddPersistence(FreeSql.DataType.SqlServer)
            .AddAPM(x => x.AddSqlSugar());

builder.Services.AddScoped<ISqlSugarClient>(s =>
    {
        SqlSugarClient sqlSugar = new SqlSugarClient(new ConnectionConfig()
        {
            DbType = DbType.SqlServer,
            ConnectionString = builder.Configuration["ConnectionStrings:Wing.Demo"],
            IsAutoCloseConnection = true,
        },
        db =>db.AddWingAPM());
        return sqlSugar;
    });

var app = builder.Build();

// Configure the HTTP request pipeline.

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();

查看运行结果

上次编辑于:
贡献者: linguicheng