From 9fda3b548c1d65eaff6bdd4b63d60244c4fe55db Mon Sep 17 00:00:00 2001 From: veysel mutlu Date: Fri, 10 Sep 2021 21:15:34 +0300 Subject: [PATCH 1/7] Added use of short foreach --- .../Catalog/Catalog.API/Controllers/CatalogController.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs b/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs index d58c06f66..f6442da39 100644 --- a/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs +++ b/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs @@ -304,10 +304,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers var baseUri = _settings.PicBaseUrl; var azureStorageEnabled = _settings.AzureStorageEnabled; - foreach (var item in items) - { - item.FillProductUrl(baseUri, azureStorageEnabled: azureStorageEnabled); - } + items.ForEach(item => { item.FillProductUrl(baseUri, azureStorageEnabled: azureStorageEnabled); }); return items; } From d20232db124735b7f5a47dba3ece6d1b05405856 Mon Sep 17 00:00:00 2001 From: veysel mutlu Date: Fri, 10 Sep 2021 21:16:44 +0300 Subject: [PATCH 2/7] Added short switch usage with .net 5 --- .../Catalog.API/Controllers/PicController.cs | 44 +++++-------------- 1 file changed, 11 insertions(+), 33 deletions(-) diff --git a/src/Services/Catalog/Catalog.API/Controllers/PicController.cs b/src/Services/Catalog/Catalog.API/Controllers/PicController.cs index 31c93683c..a66261755 100644 --- a/src/Services/Catalog/Catalog.API/Controllers/PicController.cs +++ b/src/Services/Catalog/Catalog.API/Controllers/PicController.cs @@ -56,40 +56,18 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers private string GetImageMimeTypeFromImageFileExtension(string extension) { - string mimetype; - - switch (extension) + string mimetype = extension switch { - case ".png": - mimetype = "image/png"; - break; - case ".gif": - mimetype = "image/gif"; - break; - case ".jpg": - case ".jpeg": - mimetype = "image/jpeg"; - break; - case ".bmp": - mimetype = "image/bmp"; - break; - case ".tiff": - mimetype = "image/tiff"; - break; - case ".wmf": - mimetype = "image/wmf"; - break; - case ".jp2": - mimetype = "image/jp2"; - break; - case ".svg": - mimetype = "image/svg+xml"; - break; - default: - mimetype = "application/octet-stream"; - break; - } - + ".png" => "image/png", + ".gif" => "image/gif", + ".jpg" or ".jpeg" => "image/jpeg", + ".bmp" => "image/bmp", + ".tiff" => "image/tiff", + ".wmf" => "image/wmf", + ".jp2" => "image/jp2", + ".svg" => "image/svg+xml", + _ => "application/octet-stream", + }; return mimetype; } } From 79d81f531a1e3fc32b46c0a47ae8605c3c3abc7f Mon Sep 17 00:00:00 2001 From: veysel mutlu Date: Fri, 10 Sep 2021 21:18:02 +0300 Subject: [PATCH 3/7] Replaced ternary operator with switch --- .../Catalog.API/Extensions/CatalogItemExtensions.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Services/Catalog/Catalog.API/Extensions/CatalogItemExtensions.cs b/src/Services/Catalog/Catalog.API/Extensions/CatalogItemExtensions.cs index e953df581..3ca136f12 100644 --- a/src/Services/Catalog/Catalog.API/Extensions/CatalogItemExtensions.cs +++ b/src/Services/Catalog/Catalog.API/Extensions/CatalogItemExtensions.cs @@ -6,9 +6,12 @@ { if (item != null) { - item.PictureUri = azureStorageEnabled - ? picBaseUrl + item.PictureFileName - : picBaseUrl.Replace("[0]", item.Id.ToString()); + // https://www.linkedin.com/feed/update/urn:li:activity:6841055191211491328/ + item.PictureUri = azureStorageEnabled switch + { + true => picBaseUrl + item.PictureFileName, + _ => picBaseUrl.Replace("[0]", item.Id.ToString()) + }; } } } From 4814e1bce2a7bb2dfd44c3abe5c3d8caf4af1807 Mon Sep 17 00:00:00 2001 From: veysel mutlu Date: Fri, 10 Sep 2021 22:12:46 +0300 Subject: [PATCH 4/7] The startup.cs class was purified by writing the extensions method in the field where services are registered in the startup.cs class. --- .../StartupConfigurationExtensions.cs | 85 +++++++++++++++++++ src/Services/Identity/Identity.API/Startup.cs | 72 ++-------------- 2 files changed, 91 insertions(+), 66 deletions(-) create mode 100644 src/Services/Identity/Identity.API/Extensions/StartupConfigurationExtensions.cs diff --git a/src/Services/Identity/Identity.API/Extensions/StartupConfigurationExtensions.cs b/src/Services/Identity/Identity.API/Extensions/StartupConfigurationExtensions.cs new file mode 100644 index 000000000..b19717bb1 --- /dev/null +++ b/src/Services/Identity/Identity.API/Extensions/StartupConfigurationExtensions.cs @@ -0,0 +1,85 @@ +using IdentityServer4.Services; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.eShopOnContainers.Services.Identity.API; +using Microsoft.eShopOnContainers.Services.Identity.API.Certificates; +using Microsoft.eShopOnContainers.Services.Identity.API.Data; +using Microsoft.eShopOnContainers.Services.Identity.API.Devspaces; +using Microsoft.eShopOnContainers.Services.Identity.API.Models; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Reflection; +using Microsoft.eShopOnContainers.Services.Identity.API.Services; + +namespace Identity.API.Extensions +{ + public static class StartupConfigurationExtensions + { + public static void RegisterAppInsights(this IServiceCollection services, IConfiguration configuration) + { + services.AddApplicationInsightsTelemetry(configuration); + services.AddApplicationInsightsKubernetesEnricher(); + } + + // Add framework services. + public static void ConfigureDatabase(this IServiceCollection services, IConfiguration configuration) + { + services.AddDbContext(options => + options.UseSqlServer(configuration["ConnectionString"], + sqlServerOptionsAction: sqlOptions => + { + sqlOptions.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name); + //Configuring Connection Resiliency: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency + sqlOptions.EnableRetryOnFailure(maxRetryCount: 15, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null); + })); + + services.AddIdentity() + .AddEntityFrameworkStores() + .AddDefaultTokenProviders(); + } + + // Adds IdentityServer + public static void ConfigureIdentityServer(this IServiceCollection services, IConfiguration configuration) + { + var connectionString = configuration["ConnectionString"]; + var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name; + + services.AddIdentityServer(x => + { + x.IssuerUri = "null"; + x.Authentication.CookieLifetime = TimeSpan.FromHours(2); + }) + .AddDevspacesIfNeeded(configuration.GetValue("EnableDevspaces", false)) + .AddSigningCredential(Certificate.Get()) + .AddAspNetIdentity() + .AddConfigurationStore(options => + { + options.ConfigureDbContext = builder => builder.UseSqlServer(connectionString, + sqlServerOptionsAction: sqlOptions => + { + sqlOptions.MigrationsAssembly(migrationsAssembly); + //Configuring Connection Resiliency: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency + sqlOptions.EnableRetryOnFailure(maxRetryCount: 15, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null); + }); + }) + .AddOperationalStore(options => + { + options.ConfigureDbContext = builder => builder.UseSqlServer(connectionString, + sqlServerOptionsAction: sqlOptions => + { + sqlOptions.MigrationsAssembly(migrationsAssembly); + //Configuring Connection Resiliency: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency + sqlOptions.EnableRetryOnFailure(maxRetryCount: 15, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null); + }); + }) + .Services.AddTransient(); + } + + public static void ConfigureDependecyInjections(this IServiceCollection services) + { + services.AddTransient, EFLoginService>(); + services.AddTransient(); + } + } +} diff --git a/src/Services/Identity/Identity.API/Startup.cs b/src/Services/Identity/Identity.API/Startup.cs index a161729db..d6d966d5c 100644 --- a/src/Services/Identity/Identity.API/Startup.cs +++ b/src/Services/Identity/Identity.API/Startup.cs @@ -1,18 +1,11 @@ using Autofac; using Autofac.Extensions.DependencyInjection; using HealthChecks.UI.Client; -using IdentityServer4.Services; +using Identity.API.Extensions; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Diagnostics.HealthChecks; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Identity; -using Microsoft.EntityFrameworkCore; -using Microsoft.eShopOnContainers.Services.Identity.API.Certificates; -using Microsoft.eShopOnContainers.Services.Identity.API.Data; -using Microsoft.eShopOnContainers.Services.Identity.API.Devspaces; -using Microsoft.eShopOnContainers.Services.Identity.API.Models; -using Microsoft.eShopOnContainers.Services.Identity.API.Services; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.HealthChecks; @@ -20,37 +13,22 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using StackExchange.Redis; using System; -using System.Reflection; namespace Microsoft.eShopOnContainers.Services.Identity.API { public class Startup { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } + public Startup(IConfiguration configuration) => (Configuration) = (configuration); public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { - RegisterAppInsights(services); + services.RegisterAppInsights(Configuration); // Add framework services. - services.AddDbContext(options => - options.UseSqlServer(Configuration["ConnectionString"], - sqlServerOptionsAction: sqlOptions => - { - sqlOptions.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name); - //Configuring Connection Resiliency: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency - sqlOptions.EnableRetryOnFailure(maxRetryCount: 15, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null); - })); - - services.AddIdentity() - .AddEntityFrameworkStores() - .AddDefaultTokenProviders(); + services.ConfigureDatabase(Configuration); services.Configure(Configuration); @@ -69,42 +47,10 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API name: "IdentityDB-check", tags: new string[] { "IdentityDB" }); - services.AddTransient, EFLoginService>(); - services.AddTransient(); - - var connectionString = Configuration["ConnectionString"]; - var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name; + services.ConfigureDependecyInjections(); // Adds IdentityServer - services.AddIdentityServer(x => - { - x.IssuerUri = "null"; - x.Authentication.CookieLifetime = TimeSpan.FromHours(2); - }) - .AddDevspacesIfNeeded(Configuration.GetValue("EnableDevspaces", false)) - .AddSigningCredential(Certificate.Get()) - .AddAspNetIdentity() - .AddConfigurationStore(options => - { - options.ConfigureDbContext = builder => builder.UseSqlServer(connectionString, - sqlServerOptionsAction: sqlOptions => - { - sqlOptions.MigrationsAssembly(migrationsAssembly); - //Configuring Connection Resiliency: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency - sqlOptions.EnableRetryOnFailure(maxRetryCount: 15, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null); - }); - }) - .AddOperationalStore(options => - { - options.ConfigureDbContext = builder => builder.UseSqlServer(connectionString, - sqlServerOptionsAction: sqlOptions => - { - sqlOptions.MigrationsAssembly(migrationsAssembly); - //Configuring Connection Resiliency: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency - sqlOptions.EnableRetryOnFailure(maxRetryCount: 15, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null); - }); - }) - .Services.AddTransient(); + services.ConfigureIdentityServer(Configuration); //services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0); services.AddControllers(); @@ -174,11 +120,5 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API }); }); } - - private void RegisterAppInsights(IServiceCollection services) - { - services.AddApplicationInsightsTelemetry(Configuration); - services.AddApplicationInsightsKubernetesEnricher(); - } } } From 7abd85796e7dda6f9e95ccb537949e8d6f2a4094 Mon Sep 17 00:00:00 2001 From: veysel mutlu Date: Fri, 10 Sep 2021 22:48:47 +0300 Subject: [PATCH 5/7] The repetitive fields in the configuration classes in the Ordering.Infrastructure project were gathered here by creating a base class. --- .../EntityConfigurations/BaseConfiguration.cs | 15 +++++++++++++++ .../BuyerEntityTypeConfiguration.cs | 11 ++++------- .../OrderEntityTypeConfiguration.cs | 11 +++++------ .../OrderItemEntityTypeConfiguration.cs | 11 ++++------- .../PaymentMethodEntityTypeConfiguration.cs | 11 ++++------- 5 files changed, 32 insertions(+), 27 deletions(-) create mode 100644 src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/BaseConfiguration.cs diff --git a/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/BaseConfiguration.cs b/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/BaseConfiguration.cs new file mode 100644 index 000000000..ef7cb2452 --- /dev/null +++ b/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/BaseConfiguration.cs @@ -0,0 +1,15 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork; + +namespace Ordering.Infrastructure.EntityConfigurations +{ + public class BaseConfiguration : IEntityTypeConfiguration where TEntity : Entity + { + public virtual void Configure(EntityTypeBuilder builder) + { + builder.Ignore(b => b.DomainEvents); + builder.HasKey(e => e.Id); + } + } +} diff --git a/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/BuyerEntityTypeConfiguration.cs b/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/BuyerEntityTypeConfiguration.cs index f5bdea756..95f85bc6b 100644 --- a/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/BuyerEntityTypeConfiguration.cs +++ b/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/BuyerEntityTypeConfiguration.cs @@ -5,17 +5,12 @@ using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure; namespace Ordering.Infrastructure.EntityConfigurations { - class BuyerEntityTypeConfiguration - : IEntityTypeConfiguration + class BuyerEntityTypeConfiguration : BaseConfiguration { - public void Configure(EntityTypeBuilder buyerConfiguration) + public override void Configure(EntityTypeBuilder buyerConfiguration) { buyerConfiguration.ToTable("buyers", OrderingContext.DEFAULT_SCHEMA); - buyerConfiguration.HasKey(b => b.Id); - - buyerConfiguration.Ignore(b => b.DomainEvents); - buyerConfiguration.Property(b => b.Id) .UseHiLo("buyerseq", OrderingContext.DEFAULT_SCHEMA); @@ -36,6 +31,8 @@ namespace Ordering.Infrastructure.EntityConfigurations var navigation = buyerConfiguration.Metadata.FindNavigation(nameof(Buyer.PaymentMethods)); navigation.SetPropertyAccessMode(PropertyAccessMode.Field); + + base.Configure(buyerConfiguration); } } } diff --git a/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/OrderEntityTypeConfiguration.cs b/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/OrderEntityTypeConfiguration.cs index 4e32763eb..dc0bedf45 100644 --- a/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/OrderEntityTypeConfiguration.cs +++ b/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/OrderEntityTypeConfiguration.cs @@ -7,16 +7,12 @@ using System; namespace Ordering.Infrastructure.EntityConfigurations { - class OrderEntityTypeConfiguration : IEntityTypeConfiguration + class OrderEntityTypeConfiguration : BaseConfiguration { - public void Configure(EntityTypeBuilder orderConfiguration) + public override void Configure(EntityTypeBuilder orderConfiguration) { orderConfiguration.ToTable("orders", OrderingContext.DEFAULT_SCHEMA); - orderConfiguration.HasKey(o => o.Id); - - orderConfiguration.Ignore(b => b.DomainEvents); - orderConfiguration.Property(o => o.Id) .UseHiLo("orderseq", OrderingContext.DEFAULT_SCHEMA); @@ -81,6 +77,9 @@ namespace Ordering.Infrastructure.EntityConfigurations .WithMany() // .HasForeignKey("OrderStatusId"); .HasForeignKey("_orderStatusId"); + + + base.Configure(orderConfiguration); } } } diff --git a/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/OrderItemEntityTypeConfiguration.cs b/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/OrderItemEntityTypeConfiguration.cs index 9fd5734ed..1adb30f6a 100644 --- a/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/OrderItemEntityTypeConfiguration.cs +++ b/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/OrderItemEntityTypeConfiguration.cs @@ -5,17 +5,12 @@ using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure; namespace Ordering.Infrastructure.EntityConfigurations { - class OrderItemEntityTypeConfiguration - : IEntityTypeConfiguration + class OrderItemEntityTypeConfiguration : BaseConfiguration { - public void Configure(EntityTypeBuilder orderItemConfiguration) + public override void Configure(EntityTypeBuilder orderItemConfiguration) { orderItemConfiguration.ToTable("orderItems", OrderingContext.DEFAULT_SCHEMA); - orderItemConfiguration.HasKey(o => o.Id); - - orderItemConfiguration.Ignore(b => b.DomainEvents); - orderItemConfiguration.Property(o => o.Id) .UseHiLo("orderitemseq"); @@ -54,6 +49,8 @@ namespace Ordering.Infrastructure.EntityConfigurations .UsePropertyAccessMode(PropertyAccessMode.Field) .HasColumnName("PictureUrl") .IsRequired(false); + + base.Configure(orderItemConfiguration); } } } diff --git a/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/PaymentMethodEntityTypeConfiguration.cs b/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/PaymentMethodEntityTypeConfiguration.cs index 52fdf5f24..085d2c9db 100644 --- a/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/PaymentMethodEntityTypeConfiguration.cs +++ b/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/PaymentMethodEntityTypeConfiguration.cs @@ -6,17 +6,12 @@ using System; namespace Ordering.Infrastructure.EntityConfigurations { - class PaymentMethodEntityTypeConfiguration - : IEntityTypeConfiguration + class PaymentMethodEntityTypeConfiguration : BaseConfiguration { - public void Configure(EntityTypeBuilder paymentConfiguration) + public override void Configure(EntityTypeBuilder paymentConfiguration) { paymentConfiguration.ToTable("paymentmethods", OrderingContext.DEFAULT_SCHEMA); - paymentConfiguration.HasKey(b => b.Id); - - paymentConfiguration.Ignore(b => b.DomainEvents); - paymentConfiguration.Property(b => b.Id) .UseHiLo("paymentseq", OrderingContext.DEFAULT_SCHEMA); @@ -60,6 +55,8 @@ namespace Ordering.Infrastructure.EntityConfigurations paymentConfiguration.HasOne(p => p.CardType) .WithMany() .HasForeignKey("_cardTypeId"); + + base.Configure(paymentConfiguration); } } } From 4bfa1c03df0fde4ee981c59c398f5f641f00ba50 Mon Sep 17 00:00:00 2001 From: veysel mutlu Date: Sat, 11 Sep 2021 10:10:09 +0300 Subject: [PATCH 6/7] Example short usage patterns have been added. Example abbreviations applicable to the whole project --- .../Identity.API/Devspaces/DevspacesRedirectUriValidator.cs | 5 +---- src/Services/Identity/Identity.API/Identity.API.csproj | 4 ---- .../Identity/Identity.API/Services/ProfileService.cs | 2 ++ 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Services/Identity/Identity.API/Devspaces/DevspacesRedirectUriValidator.cs b/src/Services/Identity/Identity.API/Devspaces/DevspacesRedirectUriValidator.cs index d43a9ab15..7c395f570 100644 --- a/src/Services/Identity/Identity.API/Devspaces/DevspacesRedirectUriValidator.cs +++ b/src/Services/Identity/Identity.API/Devspaces/DevspacesRedirectUriValidator.cs @@ -9,10 +9,7 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Devspaces public class DevspacesRedirectUriValidator : IRedirectUriValidator { private readonly ILogger _logger; - public DevspacesRedirectUriValidator(ILogger logger) - { - _logger = logger; - } + public DevspacesRedirectUriValidator(ILogger logger) => (_logger) = (logger); public Task IsPostLogoutRedirectUriValidAsync(string requestedUri, Client client) { diff --git a/src/Services/Identity/Identity.API/Identity.API.csproj b/src/Services/Identity/Identity.API/Identity.API.csproj index 55ad09a2d..9943c74e1 100644 --- a/src/Services/Identity/Identity.API/Identity.API.csproj +++ b/src/Services/Identity/Identity.API/Identity.API.csproj @@ -63,8 +63,4 @@ - - - - diff --git a/src/Services/Identity/Identity.API/Services/ProfileService.cs b/src/Services/Identity/Identity.API/Services/ProfileService.cs index b7637fef2..300923f63 100644 --- a/src/Services/Identity/Identity.API/Services/ProfileService.cs +++ b/src/Services/Identity/Identity.API/Services/ProfileService.cs @@ -21,6 +21,8 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Services _userManager = userManager; } + //New Method ArgumentNullException.ThrowIfNull (obj) Added to .NET 6 + //https://davidshergilashvili.space/2021/09/08/new-method-argumentnullexception-throwifnull-obj-added-to-net-6/ async public Task GetProfileDataAsync(ProfileDataRequestContext context) { var subject = context.Subject ?? throw new ArgumentNullException(nameof(context.Subject)); From 723bd1209fd6ee5bf252c11a249af9400de4e5ea Mon Sep 17 00:00:00 2001 From: veysel mutlu Date: Sat, 11 Sep 2021 10:10:14 +0300 Subject: [PATCH 7/7] Added editing for sending without writing bearer before token values sent in API requests. --- src/Services/Ordering/Ordering.API/Startup.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Services/Ordering/Ordering.API/Startup.cs b/src/Services/Ordering/Ordering.API/Startup.cs index 5813a0578..4dcfa8169 100644 --- a/src/Services/Ordering/Ordering.API/Startup.cs +++ b/src/Services/Ordering/Ordering.API/Startup.cs @@ -277,6 +277,25 @@ } }); + /* + * resource: https://twitter.com/CoderBora/status/1436392448356495362 + * Swagger => Authorization: Bearer {token} : DO YOU WANT TO WRITE "Bearer" to the Value each time? + + AddSecurityDefinition=>{ in Swagger + + Type = SecuritySchemeType Choose "Http" instead of "ApiKey". Avoid typing "Bearer" instead of token + * + */ + options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme + { + Description = @"JWT Authorization header using the Bearer scheme. Example: \'Authorization: Bearer {token}\'", + Name = "Authorization", + In = ParameterLocation.Header, + Type = SecuritySchemeType.Http, + Scheme = "Bearer" + }); + + options.OperationFilter(); });