diff --git a/MyApp/Configure.OpenApi.cs b/MyApp/Configure.OpenApi.cs new file mode 100644 index 0000000..ce354fa --- /dev/null +++ b/MyApp/Configure.OpenApi.cs @@ -0,0 +1,32 @@ +[assembly: HostingStartup(typeof(MyApp.ConfigureOpenApi))] + +namespace MyApp; + +public class ConfigureOpenApi : IHostingStartup +{ + public void Configure(IWebHostBuilder builder) => builder + .ConfigureServices((context, services) => + { + if (context.HostingEnvironment.IsDevelopment()) + { + services.AddEndpointsApiExplorer(); + services.AddSwaggerGen(); + + services.AddServiceStackSwagger(); + services.AddBasicAuth(); + //services.AddJwtAuth(); + + services.AddTransient(); + } + }); + + public class StartupFilter : IStartupFilter + { + public Action Configure(Action next) => app => + { + app.UseSwagger(); + app.UseSwaggerUI(); + next(app); + }; + } +} \ No newline at end of file diff --git a/MyApp/Controllers/HomeController.cs b/MyApp/Controllers/HomeController.cs index eb87a1d..137e8d3 100644 --- a/MyApp/Controllers/HomeController.cs +++ b/MyApp/Controllers/HomeController.cs @@ -1,19 +1,12 @@ using System.Diagnostics; using Microsoft.AspNetCore.Mvc; -using ServiceStack.Mvc; using MyApp.Models; -using ServiceStack; namespace MyApp.Controllers; -public class HomeController : ServiceStackController +public class HomeController(ILogger logger) : ServiceStackController { - private readonly ILogger _logger; - - public HomeController(ILogger logger) - { - _logger = logger; - } + private readonly ILogger _logger = logger; public IActionResult Index() => View(); diff --git a/MyApp/MyApp.csproj b/MyApp/MyApp.csproj index 7072671..40059b8 100644 --- a/MyApp/MyApp.csproj +++ b/MyApp/MyApp.csproj @@ -25,8 +25,12 @@ + + + + @@ -35,7 +39,6 @@ - diff --git a/MyApp/Program.cs b/MyApp/Program.cs index c2cd571..7ebe31b 100644 --- a/MyApp/Program.cs +++ b/MyApp/Program.cs @@ -74,15 +74,8 @@ //services.AddSingleton, EmailSender>(); services.AddScoped, AdditionalUserClaimsPrincipalFactory>(); -services.AddEndpointsApiExplorer(); -services.AddSwaggerGen(); - // Register all services -services.AddServiceStack(typeof(MyServices).Assembly, c => { - c.AddSwagger(o => { - o.AddBasicAuth(); - }); -}); +services.AddServiceStack(typeof(MyServices).Assembly); var app = builder.Build(); @@ -90,8 +83,6 @@ if (app.Environment.IsDevelopment()) { app.UseDeveloperExceptionPage(); - app.UseSwagger(); - app.UseSwaggerUI(); } else {