Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1a65cf3

Browse files
committed
#升级到.net6.0#
1 parent 717fbb7 commit 1a65cf3

File tree

4 files changed

+94
-32
lines changed

4 files changed

+94
-32
lines changed

‎APIJSON.NET/APIJSON.NET/APIJSON.NET.csproj

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>
@@ -19,19 +19,17 @@
1919
</ItemGroup>
2020

2121
<ItemGroup>
22-
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.18" />
23-
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.9" />
24-
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" />
22+
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.6" />
23+
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.6" />
24+
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.6" />
2525

26-
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
27-
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.6.3" />
28-
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="5.6.3" />
26+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
2927
</ItemGroup>
3028

3129
<ItemGroup>
3230
<ProjectReference Include="..\APIJSONCommon\ApiJson.Common.csproj" />
3331
</ItemGroup>
3432

35-
<ProjectExtensions><VisualStudio><UserPropertiesappsettings_1json__JSONSchema="http://json.schemastore.org/config" /></VisualStudio></ProjectExtensions>
33+
3634

3735
</Project>

‎APIJSON.NET/APIJSON.NET/Program.cs

Lines changed: 77 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,83 @@
1-
using Microsoft.AspNetCore;
1+
using APIJSON.NET;
2+
using APIJSON.NET.Models;
3+
using APIJSON.NET.Services;
4+
using Microsoft.AspNetCore;
5+
using Microsoft.AspNetCore.Builder;
26
using Microsoft.AspNetCore.Hosting;
7+
using Microsoft.AspNetCore.Http;
8+
using Microsoft.Extensions.DependencyInjection;
9+
using Microsoft.Extensions.Hosting;
10+
using Microsoft.IdentityModel.Tokens;
11+
using Microsoft.OpenApi.Models;
12+
using System;
13+
using System.Collections.Generic;
314
using System.Net;
15+
using System.Text;
416

5-
namespace APIJSON.NET
17+
const string _defaultCorsPolicyName = "localhost";
18+
var builder = WebApplication.CreateBuilder(args);
19+
20+
// Add services to the container.
21+
22+
builder.Services.AddControllers();
23+
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
24+
builder.Services.AddEndpointsApiExplorer();
25+
26+
builder.Services.Configure<List<Role>>(builder.Configuration.GetSection("RoleList"));
27+
builder.Services.Configure<Dictionary<string, string>>(builder.Configuration.GetSection("tablempper"));
28+
builder.Services.Configure<TokenAuthConfiguration>(tokenAuthConfig =>
629
{
7-
public class Program
30+
tokenAuthConfig.SecurityKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(builder.Configuration["Authentication:JwtBearer:SecurityKey"]));
31+
tokenAuthConfig.Issuer = builder.Configuration["Authentication:JwtBearer:Issuer"];
32+
tokenAuthConfig.Audience = builder.Configuration["Authentication:JwtBearer:Audience"];
33+
tokenAuthConfig.SigningCredentials = new SigningCredentials(tokenAuthConfig.SecurityKey, SecurityAlgorithms.HmacSha256);
34+
tokenAuthConfig.Expiration = TimeSpan.FromDays(1);
35+
});
36+
AuthConfigurer.Configure(builder.Services, builder.Configuration);
37+
38+
var origins = builder.Configuration.GetSection("CorsUrls").Value.Split(",");
39+
builder.Services.AddCors(options => options.AddPolicy(_defaultCorsPolicyName,
40+
builder =>
41+
builder.WithOrigins(origins)
42+
.AllowAnyHeader()
43+
.AllowAnyMethod().AllowCredentials()
44+
));
45+
builder.Services.AddControllers()
46+
.AddNewtonsoftJson(options =>
847
{
9-
public static void Main(string[] args)
10-
{
11-
CreateWebHostBuilder(args).Build().Run();
12-
}
13-
14-
public static IWebHostBuilder CreateWebHostBuilder(string[] args)
15-
{
16-
return WebHost.CreateDefaultBuilder(args).UseStartup<Startup>();
17-
}
18-
}
48+
options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
49+
options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
50+
}); ;
51+
builder.Services.AddSwaggerGen(c =>
52+
{
53+
c.SwaggerDoc("v1", new OpenApiInfo { Title = "APIJSON.NET", Version = "v1" });
54+
});
55+
builder.Services.AddSingleton<DbContext>();
56+
builder.Services.AddSingleton<SelectTable>();
57+
builder.Services.AddSingleton<TokenAuthConfiguration>();
58+
builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
59+
builder.Services.AddTransient<IIdentityService, IdentityService>();
60+
builder.Services.AddTransient<ITableMapper, TableMapper>();
61+
62+
63+
var app = builder.Build();
64+
65+
// Configure the HTTP request pipeline.
66+
if (app.Environment.IsDevelopment())
67+
{
68+
app.UseSwagger();
69+
app.UseSwaggerUI(c =>
70+
{
71+
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
72+
73+
});
1974
}
75+
76+
app.UseHttpsRedirection();
77+
app.UseStaticFiles();
78+
app.UseAuthorization();
79+
app.UseCors(_defaultCorsPolicyName);
80+
app.MapControllers();
81+
app.UseJwtTokenMiddleware();
82+
DbInit.Initialize(app);
83+
app.Run();

‎APIJSON.NET/APIJSON.NET/appsettings.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@
1515
},
1616
"RoleList": [
1717
{
18-
"name": "role1", //权限名称 唯一
19-
"select": { //查询权限
20-
"table": [ "*" ], //可操作的表
21-
"column": [ "*" ], //可操作的字段
18+
"name": "role1", //Ȩ������ Ψһ
19+
"select": { //��ѯȨ��
20+
"table": [ "*" ], //�ɲ����ı�
21+
"column": [ "*" ], //�ɲ������ֶ�
2222
"where": []
2323
},
24-
"update": { //修改权限
24+
"update": { //�޸�Ȩ��
2525
"table": [ "moment", "User", "Comment" ],
2626
"column": [ "*", "*", "*" ]
2727
},
28-
"insert": { //添加权限
28+
"insert": { //���Ȩ��
2929
"table": [ "moment", "User", "Comment" ],
3030
"column": [ "*", "*", "*" ]
3131
},
32-
"delete": { //删除权限
32+
"delete": { //ɾ��Ȩ��
3333
"table": [ "moment", "User", "Comment" ]
3434
}
3535
},
@@ -41,7 +41,7 @@
4141
}
4242
}
4343
],
44-
"tablempper": //别名表映射
44+
"tablempper": //������ӳ��
4545
{
4646
"user": "apijson_user",
4747
"org": "web_organization"

‎APIJSON.NET/APIJSONCommon/ApiJson.Common.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
</ItemGroup>
2121

2222
<ItemGroup>
23-
<PackageReference Include="AspectCore.Extensions.Reflection" Version="2.1.0" />
24-
<PackageReference Include="Microsoft.Extensions.Options" Version="3.1.4" />
25-
<PackageReference Include="sqlSugarCore" Version="5.0.5.5" />
23+
<PackageReference Include="AspectCore.Extensions.Reflection" Version="2.2.0" />
24+
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
25+
<PackageReference Include="sqlSugarCore" Version="5.0.9.1" />
2626
</ItemGroup>
2727

2828
<ItemGroup>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /