Skip to content

在Program.cs中

csharp
using RsCode;
using RsCode.AspNetCore;
using PetaPoco.Providers;
using AspectCore.Extensions.DependencyInjection;

var builder = WebApplication.CreateBuilder(args);
//添加RsCode
builder.Host.UseServiceProviderFactory(new DynamicProxyServiceProviderFactory());
builder.Services.AddRsCode();
//自动注册应用接口和实现
string[] assemblies = new string[] { "your.project.Core", "应用程序集名称" }; //todo 替换成实际业务类程序集名称
builder.Services.AutoInject(assemblies); 
//添加数据库,以MySql为例
builder.Services.AddDatabase<MySqlDatabaseProvider>();
builder.Services.AddUnitOfWork();



var app = builder.Build();
if (app.Environment.IsDevelopment())
{
	//启用swaggerui
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseAuthorization();

//异常处理
app.UseErrorHandler();

app.MapControllers();
app.Run();

appsettings.json中的基本配置

json
{
  "IsDebug": true,
  "CorsPolicy": [ "http://localhost:5052", "http://localhost:5000"],
  "Jwt": {
    "Issuer": "rscode.cn",
    "Audience": "rscode.cn",
    //安全码
    "SecurityKey": "rscode.cn",
    //accesstoken过期时间,单位(分钟)
    "Expire": 15
  },
  "Tencent": {
    "WeChat": [
      {
        "Id": "gh_xxxxxx",
        "AppId": "wx7c829604a62b02e8",
        "AppSecret": "",
        "Token": "xxxx",
        "EncodingAESKey": "xxxxx",
        "DataFormatter": "xml"
      }
    ]
  },
  "aliyun": {
    "accessKeyId": "LTAI5xxxxxx",
    "accessKeySecret": "AD3dLxxxxxx",
    "regionId": "cn-hangzhou",
    "oss": {
      "accessKeyId": "LTAI5xxxxxx",
      "accessKeySecret": "fb5lg9OhWxxxx",
      "roleArn": [ "acs:ram::1237672825991179:role/ramoss" ],
      "endpoint": [
        {
          "name": "cn-shanghai",
          "sts": "sts.cn-shanghai.aliyuncs.com",
          "oss": "oss-cn-shanghai.aliyuncs.com"
        }
      ]
    }
  },
  "baidu": {
    "id": "u3CsImGAwc0v",
    "secret": "S4zaAWUAzzTe15xb",
    "qianfan": {
      "key": "e7wBdLcvMLFb",
      "secret": "YrPg5RaXFR"
    }
  },
  "RedisServer": {
    "Server": "127.0.0.1:6379,password=1,defaultDatabase=db0"
  },
  //七牛存储配置
  "Storage": [
    {
      "Name": "qiniu",
      "UploadTokenUrl": "https://localhost:5001/storage/uptoken?provider=qiniu",
      "AccessKey": "xxx",
      "SecretKey": "Jxxx",
      "Domain": "https://res.rscode.cn", //云存储域名
      "Bucket": "res-rscode-cn",
      "Zone": "ZONE_CN_East", //华东 ZONE_CN_East  华北 ZONE_CN_North 华南 ZONE_CN_South  北美 ZONE_US_North
      "UploadTokenExpireTime": 30, // 上传token有效时间单位:秒
      "DownloadTokenExpireTime": 5, //下载token有效时间
      "ManageTokenExpireTime": 5 //管理token有效时间
    }
  ],
  //本地存储配置
  "LocalStorage": {
    "UploadTokenUrl": "https://localhost:5001/storage/uptoken?provider=local",
    "UploadUrl": "https://localhost:5001/storage/upload",
    "AccessKey": "", //不填
    "SecretKey": "", //不填
    "Domain": "https://localhost:5001", //上传后资源地址,例:http://res.rscode.cn
    "Bucket": "", //不填
    "Zone": "", //不填
    "UploadTokenExpireTime": 30, // 上传token有效时间单位:秒
    "DownloadTokenExpireTime": 5, //下载token有效时间
    "ManageTokenExpireTime": 5 //管理token有效时间
  },
  "ConnectionStrings": {
    "DefaultConnection": "Server=127.0.0.1;uid=root;pwd=123456;database=rswl_ai;port=3306;"
  },
  "ImServerOption": {
    "RedisClient": "127.0.0.1:6379,password=1,abortConnect=false,connectTimeout=4000,syncTimeout=5000,poolsize=10",
    "Servers": "127.0.0.1:8060", //多个ip用;分隔
    "Server": "127.0.0.1:8060"
  },
  "MQ": {
    "Name": "InMemory", //当前使用的消息队列名称
    "Storage": "MySql", //使用mysql存储消息数据
    "UseDashboard": true, //是否使用图表查看和管理消息
    "InMemory": {

    },
    "RabbitMQ": {
      "HostName": "127.0.0.1",
      "VirtualHost": "rswl",
      "UserName": "admin",
      "Password": "827*",
      "ExchangeName": "rswl_queue"
    },
    "Nats": {
      "Server": "nats://rswlabc123@127.0.0.1:4222"
    },
    "RedisStreams": {
      "Server": "127.0.0.1:6379,poolsize=10;password=1"
    },
    "Kafka": {
      "Server": "localhost:9092"
    }
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*"
}