From 05d7fad04094181c7367898f5d4af1704a4dd13a Mon Sep 17 00:00:00 2001 From: Jakub Berthoty Date: Mon, 14 Oct 2019 11:50:56 +0200 Subject: [PATCH 01/10] Kros packages update. --- .../Kros.CqrsTemplate/content/Kros.CqrsTemplate.csproj | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Kros.CqrsTemplate.csproj b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Kros.CqrsTemplate.csproj index 29d13e8..11d6169 100644 --- a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Kros.CqrsTemplate.csproj +++ b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Kros.CqrsTemplate.csproj @@ -23,12 +23,12 @@ - - - - + + + + - + From c91c977eb7c1cd80767dc7144a2168d4abc4a925 Mon Sep 17 00:00:00 2001 From: Jakub Berthoty Date: Mon, 14 Oct 2019 12:14:17 +0200 Subject: [PATCH 02/10] New KORM appsettings. --- .../content/appsettings.json | 66 ++++++++++--------- .../content/appsettings.local.json | 2 +- 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.json b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.json index 6f2c6e9..c74bf6c 100644 --- a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.json +++ b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.json @@ -1,40 +1,46 @@ { - "Logging": { - "LogLevel": { - "Default": "Warning" - } - }, + "Logging": { + "LogLevel": { + "Default": "Warning" + } + }, - "AllowedHosts": "*", + "AllowedHosts": "*", "ConnectionStrings": { "DefaultConnection": "" }, - "IdentityServerHandlers": [ - { - "AuthenticationScheme": "", - "ApiName": "", - "AuthorityUrl": "", - "Proxy": { - "Address": "" - }, - "RequireHttpsMetadata": true - } - ], + "KormSettings": { + "DefaultConnection": { + "AutoMigrate": true + } + }, + + "IdentityServerHandlers": [ + { + "AuthenticationScheme": "", + "ApiName": "", + "AuthorityUrl": "", + "Proxy": { + "Address": "" + }, + "RequireHttpsMetadata": true + } + ], - "SwaggerDocumentation": { - "Version": "v1", - "Title": "API", - "Description": "Web API.", - "Contact": { - "Name": "", - "Email": "", - "Url": "" - }, - "Extensions": { - "TokenUrl": "", - "OAuthClientId": "" - } + "SwaggerDocumentation": { + "Version": "v1", + "Title": "API", + "Description": "Web API.", + "Contact": { + "Name": "", + "Email": "", + "Url": "" + }, + "Extensions": { + "TokenUrl": "", + "OAuthClientId": "" } + } } \ No newline at end of file diff --git a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.local.json b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.local.json index 93afa42..ca6a4a7 100644 --- a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.local.json +++ b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.local.json @@ -8,6 +8,6 @@ }, "ConnectionStrings": { - "DefaultConnection": "Server={serverName};Initial Catalog={databaseName};Integrated Security=True;KormAutoMigrate=true;" + "DefaultConnection": "Server={serverName};Initial Catalog={databaseName};Integrated Security=True;" } } \ No newline at end of file From 0dfa0bb8c53d5e46660b0a353fcfb13785f8f753 Mon Sep 17 00:00:00 2001 From: Jakub Berthoty Date: Mon, 14 Oct 2019 12:25:39 +0200 Subject: [PATCH 03/10] Added ValueConverter. --- .../content/Infrastructure/DatabaseConfiguration.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Infrastructure/DatabaseConfiguration.cs b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Infrastructure/DatabaseConfiguration.cs index ec1f512..3177702 100644 --- a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Infrastructure/DatabaseConfiguration.cs +++ b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Infrastructure/DatabaseConfiguration.cs @@ -1,5 +1,6 @@ using Kros.CqrsTemplate.Domain; using Kros.KORM; +using Kros.KORM.Converter; using Kros.KORM.Metadata; namespace Kros.CqrsTemplate.Infrastructure @@ -7,7 +8,7 @@ namespace Kros.CqrsTemplate.Infrastructure /// /// Configure database for KORM. /// - public class DatabaseConfiguration: DatabaseConfigurationBase + public class DatabaseConfiguration : DatabaseConfigurationBase { /// /// Name of RRREntityNameRRR_Plural_ table in database. @@ -22,7 +23,8 @@ public override void OnModelCreating(ModelConfigurationBuilder modelBuilder) { modelBuilder.Entity() .HasTableName(RRREntityNameRRR_Plural_TableName) - .HasPrimaryKey(f => f.Id).AutoIncrement(); + .HasPrimaryKey(f => f.Id).AutoIncrement() + .UseConverterForProperties(NullAndTrimStringConverter.ConvertNull); } } } From daa8ddf72549dca03b50123c906d96ff135d36dc Mon Sep 17 00:00:00 2001 From: Jakub Berthoty Date: Mon, 14 Oct 2019 13:01:00 +0200 Subject: [PATCH 04/10] New KORM Add/Edit/Delete. --- .../RRREntityNameRRR_Repository.cs | 27 +++---------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Infrastructure/RRREntityNameRRR_Repository.cs b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Infrastructure/RRREntityNameRRR_Repository.cs index 54c4413..0fe694b 100644 --- a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Infrastructure/RRREntityNameRRR_Repository.cs +++ b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Infrastructure/RRREntityNameRRR_Repository.cs @@ -8,7 +8,7 @@ namespace Kros.CqrsTemplate.Infrastructure /// /// Repository for persistating . /// - public class RRREntityNameRRR_Repository: IRRREntityNameRRR_Repository + public class RRREntityNameRRR_Repository : IRRREntityNameRRR_Repository { private IDatabase _database; @@ -23,33 +23,14 @@ public RRREntityNameRRR_Repository(IDatabase database) /// public async Task CreateRRREntityNameRRR_Async(RRREntityNameRRR_ item) - { - var dbSet = _database.Query().AsDbSet(); - - dbSet.Add(item); - - await dbSet.CommitChangesAsync(); - } + => await _database.AddAsync(item); /// public async Task UpdateRRREntityNameRRR_Async(RRREntityNameRRR_ item) - { - var dbSet = _database - .Query() - .AsDbSet(); - - dbSet.Edit(item); - - await dbSet.CommitChangesAsync(); - } + => await _database.EditAsync(item); /// public async Task DeleteRRREntityNameRRR_Async(long id) - { - var dbSet = _database.Query().AsDbSet(); - dbSet.Delete(new RRREntityNameRRR_() { Id = id}); - - await dbSet.CommitChangesAsync(); - } + => await _database.DeleteAsync(id); } } From 9382b39dce762b840acbdc8d42e897120cd713c0 Mon Sep 17 00:00:00 2001 From: Jakub Berthoty Date: Mon, 14 Oct 2019 13:17:53 +0200 Subject: [PATCH 05/10] Added CurrentTimeValueGenerator to DatabaseConfiguration. --- .../content/Domain/RRREntityNameRRR_.cs | 13 +++++++++++-- .../content/Infrastructure/DatabaseConfiguration.cs | 4 +++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Domain/RRREntityNameRRR_.cs b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Domain/RRREntityNameRRR_.cs index 6e33468..d7e03f4 100644 --- a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Domain/RRREntityNameRRR_.cs +++ b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Domain/RRREntityNameRRR_.cs @@ -1,5 +1,4 @@ -using Kros.KORM.Metadata; -using Kros.KORM.Metadata.Attribute; +using System; namespace Kros.CqrsTemplate.Domain { @@ -12,5 +11,15 @@ public class RRREntityNameRRR_ /// Id. /// public long Id { get; set; } + + /// + /// DateTimeOffset of entity creation. + /// + public DateTimeOffset CreatedTimestamp { get; set; } + + /// + /// DateTimeOffset of last entity update. + /// + public DateTimeOffset LastModifiedTimestamp { get; set; } } } diff --git a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Infrastructure/DatabaseConfiguration.cs b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Infrastructure/DatabaseConfiguration.cs index 3177702..d8b3d84 100644 --- a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Infrastructure/DatabaseConfiguration.cs +++ b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Infrastructure/DatabaseConfiguration.cs @@ -24,7 +24,9 @@ public override void OnModelCreating(ModelConfigurationBuilder modelBuilder) modelBuilder.Entity() .HasTableName(RRREntityNameRRR_Plural_TableName) .HasPrimaryKey(f => f.Id).AutoIncrement() - .UseConverterForProperties(NullAndTrimStringConverter.ConvertNull); + .UseConverterForProperties(NullAndTrimStringConverter.ConvertNull) + .Property(f => f.CreatedTimestamp).UseCurrentTimeValueGenerator(ValueGenerated.OnInsert) + .Property(f => f.LastModifiedTimestamp).UseCurrentTimeValueGenerator(ValueGenerated.OnInsertOrUpdate); } } } From 714555a4076c874792401bfea9a83a8eb3308726 Mon Sep 17 00:00:00 2001 From: Jakub Berthoty Date: Mon, 14 Oct 2019 13:21:21 +0200 Subject: [PATCH 06/10] Added Fluent Validation Rules to Swagger. --- .../src/Kros.CqrsTemplate/content/Startup.cs | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Startup.cs b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Startup.cs index 8a55a65..37da994 100644 --- a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Startup.cs +++ b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Startup.cs @@ -1,19 +1,20 @@ -using Microsoft.AspNetCore.Builder; +using FluentValidation.AspNetCore; +using Kros.AspNetCore; +using Kros.Identity.Extensions; +using Kros.Swagger.Extensions; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.BuilderMiddlewares; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; -using FluentValidation.AspNetCore; -using Microsoft.AspNetCore.BuilderMiddlewares; -using Kros.AspNetCore; using Microsoft.Extensions.Logging; -using Kros.Swagger.Extensions; -using Kros.Identity.Extensions; +using Swashbuckle.AspNetCore.Swagger; namespace Kros.CqrsTemplate { /// /// Startup. /// - public class Startup: BaseStartup + public class Startup : BaseStartup { /// /// Ctor. @@ -44,7 +45,10 @@ public override void ConfigureServices(IServiceCollection services) .AddClasses() .AsMatchingInterface()); - services.AddSwaggerDocumentation(Configuration); + services.AddSwaggerDocumentation(Configuration, c => + { + c.AddFluentValidationRules(); + }); } /// From 204c734fa105919e3db12bb9ee2322ecd60d158b Mon Sep 17 00:00:00 2001 From: Jakub Berthoty Date: Mon, 14 Oct 2019 13:53:04 +0200 Subject: [PATCH 07/10] Health checks. --- .../Application/ServiceCollectionExtensions.cs | 15 +++++++++++++++ .../content/Kros.CqrsTemplate.csproj | 2 ++ .../src/Kros.CqrsTemplate/content/Startup.cs | 18 ++++++++++++++---- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Application/ServiceCollectionExtensions.cs b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Application/ServiceCollectionExtensions.cs index 5a1fdb2..103ea9e 100644 --- a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Application/ServiceCollectionExtensions.cs +++ b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Application/ServiceCollectionExtensions.cs @@ -4,6 +4,7 @@ using Kros.MediatR.Extensions; using MediatR; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Diagnostics.HealthChecks; using System.Reflection; namespace Microsoft.Extensions.DependencyInjection @@ -47,5 +48,19 @@ public static void AddKormDatabase(this IServiceCollection services, IConfigurat public static IServiceCollection AddMediatRDependencies(this IServiceCollection services) => services.AddMediatR(Assembly.GetExecutingAssembly()) .AddMediatRNullCheckPostProcessor(); + + /// + /// Add Health checks. + /// + /// DI container. + /// Configuration. + public static IServiceCollection AddHealthChecks(this IServiceCollection services, IConfiguration configuration) + { + return services.AddHealthChecks() + .AddCheck(" [Full API Name]", () => HealthCheckResult.Healthy(), tags: new[] { "api" }) + .AddSqlServer(configuration.GetConnectionString("DefaultConnection"), + name: $" [API Name] database", + tags: new[] { "db", "sql" }).Services; + } } } diff --git a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Kros.CqrsTemplate.csproj b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Kros.CqrsTemplate.csproj index 11d6169..bc9d7ff 100644 --- a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Kros.CqrsTemplate.csproj +++ b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Kros.CqrsTemplate.csproj @@ -20,6 +20,7 @@ + @@ -33,6 +34,7 @@ + diff --git a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Startup.cs b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Startup.cs index 37da994..6caa362 100644 --- a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Startup.cs +++ b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Startup.cs @@ -1,9 +1,11 @@ using FluentValidation.AspNetCore; using Kros.AspNetCore; +using Kros.AspNetCore.HealthChecks; using Kros.Identity.Extensions; using Kros.Swagger.Extensions; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.BuilderMiddlewares; +using Microsoft.AspNetCore.Diagnostics.HealthChecks; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -45,10 +47,12 @@ public override void ConfigureServices(IServiceCollection services) .AddClasses() .AsMatchingInterface()); - services.AddSwaggerDocumentation(Configuration, c => - { - c.AddFluentValidationRules(); - }); + services + .AddSwaggerDocumentation(Configuration, c => + { + c.AddFluentValidationRules(); + }) + .AddHealthChecks(); } /// @@ -71,6 +75,12 @@ public override void Configure(IApplicationBuilder app, ILoggerFactory loggerFac } app.UseErrorHandling(); + app.UseHealthChecks("/health", new HealthCheckOptions + { + Predicate = _ => true, + ResponseWriter = HealthCheckResponseWriter.WriteHealthCheckResponseAsync + }); + app.UseAuthentication(); app.UseKormMigrations(); app.UseMvc(); From 5734cc8792ab00c56846a0a10ad85edaf2ae4f72 Mon Sep 17 00:00:00 2001 From: Jakub Berthoty Date: Mon, 14 Oct 2019 13:59:12 +0200 Subject: [PATCH 08/10] Added Application Insights. --- .../src/Kros.CqrsTemplate/content/Kros.CqrsTemplate.csproj | 1 + .../src/Kros.CqrsTemplate/content/Startup.cs | 3 ++- .../src/Kros.CqrsTemplate/content/appsettings.json | 5 +++++ .../src/Kros.CqrsTemplate/content/appsettings.local.json | 4 ++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Kros.CqrsTemplate.csproj b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Kros.CqrsTemplate.csproj index bc9d7ff..a737002 100644 --- a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Kros.CqrsTemplate.csproj +++ b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Kros.CqrsTemplate.csproj @@ -23,6 +23,7 @@ + diff --git a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Startup.cs b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Startup.cs index 6caa362..83bc6b0 100644 --- a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Startup.cs +++ b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Startup.cs @@ -52,7 +52,8 @@ public override void ConfigureServices(IServiceCollection services) { c.AddFluentValidationRules(); }) - .AddHealthChecks(); + .AddHealthChecks(Configuration) + .AddApplicationInsights(Configuration); } /// diff --git a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.json b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.json index c74bf6c..796383f 100644 --- a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.json +++ b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.json @@ -29,6 +29,11 @@ } ], + "ApplicationInsights": { + "ServiceName": "Kros.MyWeb", + "InstrumentationKey": "" + }, + "SwaggerDocumentation": { "Version": "v1", "Title": "API", diff --git a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.local.json b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.local.json index ca6a4a7..9d5927f 100644 --- a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.local.json +++ b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.local.json @@ -9,5 +9,9 @@ "ConnectionStrings": { "DefaultConnection": "Server={serverName};Initial Catalog={databaseName};Integrated Security=True;" + }, + + "ApplicationInsights": { + "InstrumentationKey": "{instrumentationKey}" } } \ No newline at end of file From d3d92d37d32c59b9a12951fb7eb90c0adcb5eb94 Mon Sep 17 00:00:00 2001 From: Jakub Berthoty Date: Mon, 14 Oct 2019 14:26:00 +0200 Subject: [PATCH 09/10] Added Jwt Authorization. --- .../Controllers/RRREntityNameRRR_Plural_Controller.cs | 3 +++ .../Application/Controllers/SecurityTestController.cs | 7 ++++--- .../src/Kros.CqrsTemplate/content/Startup.cs | 3 +++ .../content/appsettings.Development.json | 9 +++++++++ .../src/Kros.CqrsTemplate/content/appsettings.json | 5 +++++ .../src/Kros.CqrsTemplate/content/appsettings.local.json | 4 ---- 6 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Application/Controllers/RRREntityNameRRR_Plural_Controller.cs b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Application/Controllers/RRREntityNameRRR_Plural_Controller.cs index 70214e7..d385432 100644 --- a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Application/Controllers/RRREntityNameRRR_Plural_Controller.cs +++ b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Application/Controllers/RRREntityNameRRR_Plural_Controller.cs @@ -1,6 +1,8 @@ using Kros.AspNetCore; +using Kros.AspNetCore.Authorization; using Kros.CqrsTemplate.Application.Commands; using Kros.CqrsTemplate.Application.Queries; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; @@ -11,6 +13,7 @@ namespace Kros.CqrsTemplate.Application.Controllers /// /// RRREntityNameRRR_Plural_ controller /// + [Authorize(AuthenticationSchemes = JwtAuthorizationHelper.JwtSchemeName)] [ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(ValidationProblemDetails))] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status403Forbidden)] diff --git a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Application/Controllers/SecurityTestController.cs b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Application/Controllers/SecurityTestController.cs index 75954e4..bc11cc8 100644 --- a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Application/Controllers/SecurityTestController.cs +++ b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Application/Controllers/SecurityTestController.cs @@ -1,14 +1,15 @@ -using Microsoft.AspNetCore.Authorization; +using Kros.AspNetCore; +using Kros.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using Kros.AspNetCore.Authorization; -using Kros.AspNetCore; namespace Kros.CqrsTemplate.Application.Controllers { /// /// SecurityTest controller. /// + [Authorize(AuthenticationSchemes = JwtAuthorizationHelper.JwtSchemeName)] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] public class SecurityTestController : ApiBaseController diff --git a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Startup.cs b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Startup.cs index 83bc6b0..689dbc9 100644 --- a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Startup.cs +++ b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Startup.cs @@ -1,5 +1,6 @@ using FluentValidation.AspNetCore; using Kros.AspNetCore; +using Kros.AspNetCore.Authorization; using Kros.AspNetCore.HealthChecks; using Kros.Identity.Extensions; using Kros.Swagger.Extensions; @@ -39,6 +40,8 @@ public override void ConfigureServices(IServiceCollection services) services.AddWebApi() .AddFluentValidation(); + services.AddApiJwtAuthentication(JwtAuthorizationHelper.JwtSchemeName, Configuration); + services.AddKormDatabase(Configuration); services.AddMediatRDependencies(); diff --git a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.Development.json b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.Development.json index e203e94..b7e66e1 100644 --- a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.Development.json +++ b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.Development.json @@ -5,5 +5,14 @@ "System": "Information", "Microsoft": "Information" } + }, + + "ApiJwtAuthorization": { + "JwtSecret": "{secret}", + "RequireHttpsMetadata": true + }, + + "ApplicationInsights": { + "InstrumentationKey": "{instrumentationKey}" } } diff --git a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.json b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.json index 796383f..11baa70 100644 --- a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.json +++ b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.json @@ -29,6 +29,11 @@ } ], + "ApiJwtAuthorization": { + "JwtSecret": "", + "RequireHttpsMetadata": true + }, + "ApplicationInsights": { "ServiceName": "Kros.MyWeb", "InstrumentationKey": "" diff --git a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.local.json b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.local.json index 9d5927f..ca6a4a7 100644 --- a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.local.json +++ b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.local.json @@ -9,9 +9,5 @@ "ConnectionStrings": { "DefaultConnection": "Server={serverName};Initial Catalog={databaseName};Integrated Security=True;" - }, - - "ApplicationInsights": { - "InstrumentationKey": "{instrumentationKey}" } } \ No newline at end of file From c015e5ab480b61228a0892920bb4a18acf4a848c Mon Sep 17 00:00:00 2001 From: Jakub Berthoty Date: Wed, 16 Oct 2019 07:18:38 +0200 Subject: [PATCH 10/10] PR suggestions. --- .../src/Kros.CqrsTemplate/Kros.CqrsTemplate.nuspec | 2 +- .../Application/ServiceCollectionExtensions.cs | 12 +++++++----- .../src/Kros.CqrsTemplate/content/Startup.cs | 3 --- .../src/Kros.CqrsTemplate/content/appsettings.json | 14 +------------- 4 files changed, 9 insertions(+), 22 deletions(-) diff --git a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/Kros.CqrsTemplate.nuspec b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/Kros.CqrsTemplate.nuspec index b87e59a..3b8429f 100644 --- a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/Kros.CqrsTemplate.nuspec +++ b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/Kros.CqrsTemplate.nuspec @@ -2,7 +2,7 @@ Kros.Templates.CqrsProject - 1.1.0 + 1.2.0 Create ASP.NET Web project by CQRS pattern. diff --git a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Application/ServiceCollectionExtensions.cs b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Application/ServiceCollectionExtensions.cs index 103ea9e..a62d1c0 100644 --- a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Application/ServiceCollectionExtensions.cs +++ b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Application/ServiceCollectionExtensions.cs @@ -14,6 +14,10 @@ namespace Microsoft.Extensions.DependencyInjection /// public static class ServiceCollectionExtensions { + private const string ApiName = "Kros.CqrsTemplate Api"; + private const string ApiVersion = "v1"; + private const string FullApiName = ApiName + " " + ApiVersion; + /// /// Register fluent validation. /// @@ -55,12 +59,10 @@ public static IServiceCollection AddMediatRDependencies(this IServiceCollection /// DI container. /// Configuration. public static IServiceCollection AddHealthChecks(this IServiceCollection services, IConfiguration configuration) - { - return services.AddHealthChecks() - .AddCheck(" [Full API Name]", () => HealthCheckResult.Healthy(), tags: new[] { "api" }) + => services.AddHealthChecks() + .AddCheck($" {FullApiName}", () => HealthCheckResult.Healthy(), tags: new[] { "api" }) .AddSqlServer(configuration.GetConnectionString("DefaultConnection"), - name: $" [API Name] database", + name: $" {ApiName} database", tags: new[] { "db", "sql" }).Services; - } } } diff --git a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Startup.cs b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Startup.cs index 689dbc9..25cb845 100644 --- a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Startup.cs +++ b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Startup.cs @@ -2,7 +2,6 @@ using Kros.AspNetCore; using Kros.AspNetCore.Authorization; using Kros.AspNetCore.HealthChecks; -using Kros.Identity.Extensions; using Kros.Swagger.Extensions; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.BuilderMiddlewares; @@ -35,8 +34,6 @@ public override void ConfigureServices(IServiceCollection services) { base.ConfigureServices(services); - services.AddIdentityServerAuthentication(Configuration); - services.AddWebApi() .AddFluentValidation(); diff --git a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.json b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.json index 11baa70..ebb5edb 100644 --- a/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.json +++ b/Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/appsettings.json @@ -17,25 +17,13 @@ } }, - "IdentityServerHandlers": [ - { - "AuthenticationScheme": "", - "ApiName": "", - "AuthorityUrl": "", - "Proxy": { - "Address": "" - }, - "RequireHttpsMetadata": true - } - ], - "ApiJwtAuthorization": { "JwtSecret": "", "RequireHttpsMetadata": true }, "ApplicationInsights": { - "ServiceName": "Kros.MyWeb", + "ServiceName": "Kros.CqrsTemplate", "InstrumentationKey": "" },