Skip to content

Commit

Permalink
Merge pull request #18 from kubinko/Version1_2_0
Browse files Browse the repository at this point in the history
Version 1.2.0
  • Loading branch information
Burgyn authored Oct 16, 2019
2 parents a16f214 + c015e5a commit 83404d9
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>Kros.Templates.CqrsProject</id>
<version>1.1.0</version>
<version>1.2.0</version>
<description>
Create ASP.NET Web project by CQRS pattern.
</description>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,6 +13,7 @@ namespace Kros.CqrsTemplate.Application.Controllers
/// <summary>
/// RRREntityNameRRR_Plural_ controller
/// </summary>
[Authorize(AuthenticationSchemes = JwtAuthorizationHelper.JwtSchemeName)]
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(ValidationProblemDetails))]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// SecurityTest controller.
/// </summary>
[Authorize(AuthenticationSchemes = JwtAuthorizationHelper.JwtSchemeName)]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
public class SecurityTestController : ApiBaseController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -13,6 +14,10 @@ namespace Microsoft.Extensions.DependencyInjection
/// </summary>
public static class ServiceCollectionExtensions
{
private const string ApiName = "Kros.CqrsTemplate Api";
private const string ApiVersion = "v1";
private const string FullApiName = ApiName + " " + ApiVersion;

/// <summary>
/// Register fluent validation.
/// </summary>
Expand Down Expand Up @@ -47,5 +52,17 @@ public static void AddKormDatabase(this IServiceCollection services, IConfigurat
public static IServiceCollection AddMediatRDependencies(this IServiceCollection services)
=> services.AddMediatR(Assembly.GetExecutingAssembly())
.AddMediatRNullCheckPostProcessor();

/// <summary>
/// Add Health checks.
/// </summary>
/// <param name="services">DI container.</param>
/// <param name="configuration">Configuration.</param>
public static IServiceCollection AddHealthChecks(this IServiceCollection services, IConfiguration configuration)
=> services.AddHealthChecks()
.AddCheck($" {FullApiName}", () => HealthCheckResult.Healthy(), tags: new[] { "api" })
.AddSqlServer(configuration.GetConnectionString("DefaultConnection"),
name: $" {ApiName} database",
tags: new[] { "db", "sql" }).Services;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Kros.KORM.Metadata;
using Kros.KORM.Metadata.Attribute;
using System;

namespace Kros.CqrsTemplate.Domain
{
Expand All @@ -12,5 +11,15 @@ public class RRREntityNameRRR_
/// Id.
/// </summary>
public long Id { get; set; }

/// <summary>
/// DateTimeOffset of entity creation.
/// </summary>
public DateTimeOffset CreatedTimestamp { get; set; }

/// <summary>
/// DateTimeOffset of last entity update.
/// </summary>
public DateTimeOffset LastModifiedTimestamp { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using Kros.CqrsTemplate.Domain;
using Kros.KORM;
using Kros.KORM.Converter;
using Kros.KORM.Metadata;

namespace Kros.CqrsTemplate.Infrastructure
{
/// <summary>
/// Configure database for KORM.
/// </summary>
public class DatabaseConfiguration: DatabaseConfigurationBase
public class DatabaseConfiguration : DatabaseConfigurationBase
{
/// <summary>
/// Name of RRREntityNameRRR_Plural_ table in database.
Expand All @@ -22,7 +23,10 @@ public override void OnModelCreating(ModelConfigurationBuilder modelBuilder)
{
modelBuilder.Entity<RRREntityNameRRR_>()
.HasTableName(RRREntityNameRRR_Plural_TableName)
.HasPrimaryKey(f => f.Id).AutoIncrement();
.HasPrimaryKey(f => f.Id).AutoIncrement()
.UseConverterForProperties<string>(NullAndTrimStringConverter.ConvertNull)
.Property(f => f.CreatedTimestamp).UseCurrentTimeValueGenerator(ValueGenerated.OnInsert)
.Property(f => f.LastModifiedTimestamp).UseCurrentTimeValueGenerator(ValueGenerated.OnInsertOrUpdate);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Kros.CqrsTemplate.Infrastructure
/// <summary>
/// Repository for persistating <see cref="RRREntityNameRRR_"/>.
/// </summary>
public class RRREntityNameRRR_Repository: IRRREntityNameRRR_Repository
public class RRREntityNameRRR_Repository : IRRREntityNameRRR_Repository
{
private IDatabase _database;

Expand All @@ -23,33 +23,14 @@ public RRREntityNameRRR_Repository(IDatabase database)

/// <inheritdoc />
public async Task CreateRRREntityNameRRR_Async(RRREntityNameRRR_ item)
{
var dbSet = _database.Query<RRREntityNameRRR_>().AsDbSet();

dbSet.Add(item);

await dbSet.CommitChangesAsync();
}
=> await _database.AddAsync(item);

/// <inheritdoc />
public async Task UpdateRRREntityNameRRR_Async(RRREntityNameRRR_ item)
{
var dbSet = _database
.Query<RRREntityNameRRR_>()
.AsDbSet();

dbSet.Edit(item);

await dbSet.CommitChangesAsync();
}
=> await _database.EditAsync(item);

/// <inheritdoc />
public async Task DeleteRRREntityNameRRR_Async(long id)
{
var dbSet = _database.Query<RRREntityNameRRR_>().AsDbSet();
dbSet.Delete(new RRREntityNameRRR_() { Id = id});

await dbSet.CommitChangesAsync();
}
=> await _database.DeleteAsync<RRREntityNameRRR_>(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,22 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="2.2.1" />
<PackageReference Include="FluentValidation" Version="8.4.0" />
<PackageReference Include="FluentValidation.AspNetCore" Version="8.4.0" />
<PackageReference Include="Kros.ApplicationInsights.Extensions" Version="1.0.0" />
<PackageReference Include="Kros.Identity.Extensions" Version="0.4.1" />
<PackageReference Include="Kros.AspNetCore" Version="1.1.7" />
<PackageReference Include="Kros.KORM" Version="4.0.0-alpha.8" />
<PackageReference Include="Kros.KORM.Extensions.Asp" Version="1.1.0-alpha.3" />
<PackageReference Include="Kros.MediatR.Extensions" Version="1.1.0-alpha4" />
<PackageReference Include="Kros.AspNetCore" Version="1.5.0" />
<PackageReference Include="Kros.KORM" Version="4.0.0-alpha.11" />
<PackageReference Include="Kros.KORM.Extensions.Asp" Version="1.1.0-alpha.4" />
<PackageReference Include="Kros.MediatR.Extensions" Version="1.1.0-alpha5" />
<PackageReference Include="Kros.Swagger.Extensions" Version="1.0.0" />
<PackageReference Include="Kros.Utils" Version="1.9.0" />
<PackageReference Include="Kros.Utils" Version="1.10.0" />
<PackageReference Include="Mapster" Version="4.1.0" />
<PackageReference Include="MediatR.Extensions.Microsoft.AspNetCore.Mvc" Version="2.0.0" />
<PackageReference Include="MicroElements.Swashbuckle.FluentValidation" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.7" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Cors" Version="2.2.0" />
Expand Down
35 changes: 25 additions & 10 deletions Kros.ProjectTemplates/src/Kros.CqrsTemplate/content/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
using Microsoft.AspNetCore.Builder;
using FluentValidation.AspNetCore;
using Kros.AspNetCore;
using Kros.AspNetCore.Authorization;
using Kros.AspNetCore.HealthChecks;
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 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
{
/// <summary>
/// Startup.
/// </summary>
public class Startup: BaseStartup
public class Startup : BaseStartup
{
/// <summary>
/// Ctor.
Expand All @@ -31,11 +34,11 @@ public override void ConfigureServices(IServiceCollection services)
{
base.ConfigureServices(services);

services.AddIdentityServerAuthentication(Configuration);

services.AddWebApi()
.AddFluentValidation();

services.AddApiJwtAuthentication(JwtAuthorizationHelper.JwtSchemeName, Configuration);

services.AddKormDatabase(Configuration);
services.AddMediatRDependencies();

Expand All @@ -44,7 +47,13 @@ public override void ConfigureServices(IServiceCollection services)
.AddClasses()
.AsMatchingInterface());

services.AddSwaggerDocumentation(Configuration);
services
.AddSwaggerDocumentation(Configuration, c =>
{
c.AddFluentValidationRules();
})
.AddHealthChecks(Configuration)
.AddApplicationInsights(Configuration);
}

/// <summary>
Expand All @@ -67,6 +76,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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,14 @@
"System": "Information",
"Microsoft": "Information"
}
},

"ApiJwtAuthorization": {
"JwtSecret": "{secret}",
"RequireHttpsMetadata": true
},

"ApplicationInsights": {
"InstrumentationKey": "{instrumentationKey}"
}
}
Original file line number Diff line number Diff line change
@@ -1,40 +1,44 @@
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},

"AllowedHosts": "*",
"AllowedHosts": "*",

"ConnectionStrings": {
"DefaultConnection": ""
},

"IdentityServerHandlers": [
{
"AuthenticationScheme": "",
"ApiName": "",
"AuthorityUrl": "",
"Proxy": {
"Address": ""
},
"RequireHttpsMetadata": true
}
],
"KormSettings": {
"DefaultConnection": {
"AutoMigrate": true
}
},

"ApiJwtAuthorization": {
"JwtSecret": "",
"RequireHttpsMetadata": true
},

"SwaggerDocumentation": {
"Version": "v1",
"Title": "API",
"Description": "Web API.",
"Contact": {
"Name": "",
"Email": "",
"Url": ""
},
"Extensions": {
"TokenUrl": "",
"OAuthClientId": ""
}
"ApplicationInsights": {
"ServiceName": "Kros.CqrsTemplate",
"InstrumentationKey": ""
},

"SwaggerDocumentation": {
"Version": "v1",
"Title": "API",
"Description": "Web API.",
"Contact": {
"Name": "",
"Email": "",
"Url": ""
},
"Extensions": {
"TokenUrl": "",
"OAuthClientId": ""
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;"
}
}

0 comments on commit 83404d9

Please sign in to comment.