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/MyApp.csproj b/MyApp/MyApp.csproj index c9e2c10..b56aca1 100644 --- a/MyApp/MyApp.csproj +++ b/MyApp/MyApp.csproj @@ -21,8 +21,12 @@ + + + + @@ -32,7 +36,6 @@ - diff --git a/MyApp/Program.cs b/MyApp/Program.cs index 672a7a1..43cfd2a 100644 --- a/MyApp/Program.cs +++ b/MyApp/Program.cs @@ -29,7 +29,6 @@ options.DefaultScheme = IdentityConstants.ApplicationScheme; options.DefaultSignInScheme = IdentityConstants.ExternalScheme; }) - .AddBasicAuth() .AddIdentityCookies(); services.AddDataProtection() .PersistKeysToFileSystem(new DirectoryInfo("App_Data")); @@ -58,14 +57,7 @@ services.AddBlazorServerIdentityApiClient(baseUrl); services.AddLocalStorage(); -services.AddEndpointsApiExplorer(); -services.AddSwaggerGen(); - -services.AddServiceStack(typeof(MyServices).Assembly, c => { - c.AddSwagger(o => { - o.AddBasicAuth(); - }); -}); +services.AddServiceStack(typeof(MyServices).Assembly); var app = builder.Build(); @@ -73,8 +65,6 @@ if (app.Environment.IsDevelopment()) { app.UseMigrationsEndPoint(); - app.UseSwagger(); - app.UseSwaggerUI(); } else {