From 3cd8e9b86c63e8eb6e25d65378546afd0042423c Mon Sep 17 00:00:00 2001 From: Demis Bellot Date: Tue, 6 Feb 2024 15:11:43 +0800 Subject: [PATCH] Upgrade to v8.1 --- MyApp.ServiceModel/Hello.cs | 7 +++---- MyApp/Configure.AppHost.cs | 15 ++++----------- MyApp/MyApp.csproj | 4 ++++ MyApp/Program.cs | 30 +++++++++++++++++++++++++----- MyApp/wwwroot/index.html | 9 ++++++--- MyApp/wwwroot/js/dtos.mjs | 6 +++--- 6 files changed, 45 insertions(+), 26 deletions(-) diff --git a/MyApp.ServiceModel/Hello.cs b/MyApp.ServiceModel/Hello.cs index 349e111..517b28b 100644 --- a/MyApp.ServiceModel/Hello.cs +++ b/MyApp.ServiceModel/Hello.cs @@ -2,14 +2,13 @@ namespace MyApp.ServiceModel; -[Route("/hello")] [Route("/hello/{Name}")] -public class Hello : IReturn +public class Hello : IGet, IReturn { - public string Name { get; set; } + public required string Name { get; set; } } public class HelloResponse { - public string Result { get; set; } + public required string Result { get; set; } } diff --git a/MyApp/Configure.AppHost.cs b/MyApp/Configure.AppHost.cs index a5515f1..7bd57f8 100644 --- a/MyApp/Configure.AppHost.cs +++ b/MyApp/Configure.AppHost.cs @@ -1,25 +1,18 @@ -using Funq; -using ServiceStack; -using MyApp.ServiceInterface; - -[assembly: HostingStartup(typeof(MyApp.AppHost))] +[assembly: HostingStartup(typeof(MyApp.AppHost))] namespace MyApp; -public class AppHost : AppHostBase, IHostingStartup +public class AppHost() : AppHostBase("MyApp"), IHostingStartup { public void Configure(IWebHostBuilder builder) => builder .ConfigureServices(services => { // Configure ASP.NET Core IOC Dependencies }); - public AppHost() : base("MyApp", typeof(MyServices).Assembly) {} - - public override void Configure(Container container) + public override void Configure() { - // Configure ServiceStack only IOC, Config & Plugins + // Configure ServiceStack, Run custom logic after ASP.NET Core Startup SetConfig(new HostConfig { - UseSameSiteCookies = true, }); } } diff --git a/MyApp/MyApp.csproj b/MyApp/MyApp.csproj index 50f9763..5fad293 100644 --- a/MyApp/MyApp.csproj +++ b/MyApp/MyApp.csproj @@ -12,7 +12,11 @@ + + + + diff --git a/MyApp/Program.cs b/MyApp/Program.cs index 8dddf52..d13d278 100644 --- a/MyApp/Program.cs +++ b/MyApp/Program.cs @@ -1,15 +1,35 @@ -var builder = WebApplication.CreateBuilder(args); +using MyApp.ServiceInterface; + +var builder = WebApplication.CreateBuilder(args); +var services = builder.Services; + +services.AddServiceStack(typeof(MyServices).Assembly, c => +{ + c.AddSwagger(); +}); + +services.AddEndpointsApiExplorer(); +services.AddSwaggerGen(); var app = builder.Build(); // Configure the HTTP request pipeline. -if (!app.Environment.IsDevelopment()) +if (app.Environment.IsDevelopment()) { - app.UseExceptionHandler("/Error"); + app.UseSwagger(); + app.UseSwaggerUI(); +} +else +{ + app.UseExceptionHandler("/Error", createScopeForErrors: true); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); - app.UseHttpsRedirection(); } -app.UseServiceStack(new AppHost()); + +app.UseStaticFiles(); + +app.UseServiceStack(new AppHost(), options => { + options.MapEndpoints(); +}); app.Run(); \ No newline at end of file diff --git a/MyApp/wwwroot/index.html b/MyApp/wwwroot/index.html index fe703df..1252b8a 100644 --- a/MyApp/wwwroot/index.html +++ b/MyApp/wwwroot/index.html @@ -12,7 +12,6 @@ h2, h3, strong { font-weight:500 } -