|
|
|
@ -1,5 +1,8 @@ |
|
|
|
|
|
|
|
|
|
using AspNetCoreApi.DbContexts; |
|
|
|
|
using AspNetCoreApi.Middlewares; |
|
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
|
using Pomelo.EntityFrameworkCore.MySql; |
|
|
|
|
|
|
|
|
|
namespace AspNetCoreApi |
|
|
|
|
{ |
|
|
|
@ -9,6 +12,15 @@ namespace AspNetCoreApi |
|
|
|
|
{ |
|
|
|
|
var builder = WebApplication.CreateBuilder(args); |
|
|
|
|
|
|
|
|
|
// Add EF context |
|
|
|
|
var connString = "server=peacecloud.synology.me;port=23306;database=Study;uid=study;password=Study1234!"; |
|
|
|
|
var dbServerVersion = new MySqlServerVersion(new Version(10, 3, 32)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
builder.Services.AddDbContext<AppDbContext>( |
|
|
|
|
options => options |
|
|
|
|
.UseMySql(connString, dbServerVersion)); |
|
|
|
|
|
|
|
|
|
// Add services to the container. |
|
|
|
|
|
|
|
|
|
builder.Services.AddControllers(); |
|
|
|
@ -34,20 +46,22 @@ namespace AspNetCoreApi |
|
|
|
|
|
|
|
|
|
app.UseAuthorization(); |
|
|
|
|
|
|
|
|
|
app.UseRouting(); |
|
|
|
|
app.UseEndpoints(endpoints => |
|
|
|
|
{ |
|
|
|
|
endpoints.MapGet("/routingtest", async context => |
|
|
|
|
{ |
|
|
|
|
await context.Response.WriteAsync("Hello, World!"); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
endpoints.MapGet("/routingtest/hello/{name}", async context => |
|
|
|
|
{ |
|
|
|
|
var name = context.Request.RouteValues["name"]; |
|
|
|
|
await context.Response.WriteAsync($"Hello, {name}!"); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
//// Add Routing |
|
|
|
|
//app.UseRouting(); |
|
|
|
|
//app.UseEndpoints(endpoints => |
|
|
|
|
//{ |
|
|
|
|
// endpoints.MapGet("/routingtest", async context => |
|
|
|
|
// { |
|
|
|
|
// await context.Response.WriteAsync("Hello, World!"); |
|
|
|
|
// }); |
|
|
|
|
|
|
|
|
|
// endpoints.MapGet("/routingtest/hello/{name}", async context => |
|
|
|
|
// { |
|
|
|
|
// var name = context.Request.RouteValues["name"]; |
|
|
|
|
// await context.Response.WriteAsync($"Hello, {name}!"); |
|
|
|
|
// }); |
|
|
|
|
//}); |
|
|
|
|
|
|
|
|
|
app.MapControllers(); |
|
|
|
|
|
|
|
|
|