Skip to content

Commit c4c1172

Browse files
Merge pull request #219 from AntonioFalcao/release
Updating
2 parents e5753d2 + 0330fda commit c4c1172

34 files changed

+1627
-1561
lines changed

.github/workflows/build-and-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Setup .NET Core
1414
uses: actions/setup-dotnet@v1
1515
with:
16-
dotnet-version: 6.0.100-preview.2.21155.3
16+
dotnet-version: 6.0.100-preview.4.21255.9
1717
- name: Install dependencies
1818
run: dotnet restore -v m
1919
- name: Build
@@ -28,6 +28,6 @@ jobs:
2828
- name: Setup .NET Core
2929
uses: actions/setup-dotnet@v1
3030
with:
31-
dotnet-version: 6.0.100-preview.2.21155.3
31+
dotnet-version: 6.0.100-preview.4.21255.9
3232
- name: Test
3333
run: dotnet test --no-restore -v m

Directory.Build.props

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
1-
<Project>
2-
3-
<PropertyGroup Label="Common properties">
4-
<TargetFramework>net6.0</TargetFramework>
5-
<LangVersion>9</LangVersion>
6-
</PropertyGroup>
7-
8-
<PropertyGroup Label="Packages dependency versions">
9-
10-
<!--Microsoft-->
11-
<Microsoft_Extensions_Version>6.0.0-preview.3.21201.4</Microsoft_Extensions_Version>
12-
13-
<!--EF Core-->
14-
<Microsoft_EntityFrameworkCore_Version>6.0.0-preview.3.21201.2</Microsoft_EntityFrameworkCore_Version>
15-
<Microsoft_EntityFrameworkCore_DependencyInjection_Version>6.0.0-preview.2.21154.6</Microsoft_EntityFrameworkCore_DependencyInjection_Version>
16-
<Microsoft_HealthChecks_EntityFrameworkCore_Version>6.0.0-preview.3.21201.13</Microsoft_HealthChecks_EntityFrameworkCore_Version>
17-
18-
<!--GraphQL-->
19-
<GraphQL_Server_Version>5.0.2</GraphQL_Server_Version>
20-
<GraphQL_Client_Version>3.2.3</GraphQL_Client_Version>
21-
<GraphQL_Version>4.4.0</GraphQL_Version>
22-
23-
<!--AutoMapper-->
24-
<AutoMapper_DependencyInjection_Version>8.1.1</AutoMapper_DependencyInjection_Version>
25-
<AutoMapper_Version>10.1.1</AutoMapper_Version>
26-
27-
<!--Serilog-->
28-
<Serilog_Version>4.1.0</Serilog_Version>
29-
30-
<!--HealthChecks-->
31-
<HealthChecks_Version>5.0.1</HealthChecks_Version>
32-
33-
<!--Others-->
34-
<FluentValidation_Version>10.0.4</FluentValidation_Version>
35-
<Scrutor_Version>3.3.0</Scrutor_Version>
36-
37-
</PropertyGroup>
38-
39-
</Project>
1+
<Project>
2+
3+
<PropertyGroup Label="Common properties">
4+
<TargetFramework>net6.0</TargetFramework>
5+
<LangVersion>9</LangVersion>
6+
</PropertyGroup>
7+
8+
<PropertyGroup Label="Packages dependency versions">
9+
10+
<!--Microsoft-->
11+
<Microsoft_Extensions_Version>6.0.0-preview.4.21253.7</Microsoft_Extensions_Version>
12+
13+
<!--EF Core-->
14+
<Microsoft_EntityFrameworkCore_Version>6.0.0-preview.4.21253.1</Microsoft_EntityFrameworkCore_Version>
15+
<Microsoft_EntityFrameworkCore_DependencyInjection_Version>6.0.0-preview.2.21154.6</Microsoft_EntityFrameworkCore_DependencyInjection_Version>
16+
<Microsoft_HealthChecks_EntityFrameworkCore_Version>6.0.0-preview.4.21253.5</Microsoft_HealthChecks_EntityFrameworkCore_Version>
17+
18+
<!--GraphQL-->
19+
<GraphQL_Server_Version>5.0.2</GraphQL_Server_Version>
20+
<GraphQL_Client_Version>3.2.3</GraphQL_Client_Version>
21+
<GraphQL_Version>4.5.0</GraphQL_Version>
22+
23+
<!--AutoMapper-->
24+
<AutoMapper_DependencyInjection_Version>8.1.1</AutoMapper_DependencyInjection_Version>
25+
<AutoMapper_Version>10.1.1</AutoMapper_Version>
26+
27+
<!--Serilog-->
28+
<Serilog_Version>4.1.0</Serilog_Version>
29+
30+
<!--HealthChecks-->
31+
<HealthChecks_Version>5.0.1</HealthChecks_Version>
32+
33+
<!--Others-->
34+
<FluentValidation_Version>10.2.1</FluentValidation_Version>
35+
<Scrutor_Version>3.3.0</Scrutor_Version>
36+
37+
</PropertyGroup>
38+
39+
</Project>

README.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,6 @@ app.UseGraphQLPlayground(
197197

198198
Based on cloud-native concepts, **Readiness** and **Liveness** integrity verification strategies were implemented.
199199

200-
If using [xabarilcoding/healthchecksui](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/blob/master/doc/ui-docker.md) container image it will responde on `http://localhost:8000/healthchecks-ui/`.
201-
202200
> `/health`
203201
> Just check if the instance is running.
204202

@@ -208,14 +206,26 @@ If using [xabarilcoding/healthchecksui](https://github.com/Xabaril/AspNetCore.Di
208206
> `/health/ready`
209207
> Check if the instance and all the dependencies are ready to attend to all functionalities.
210208

211-
> `/healthz`
212-
> HealthReport specific for HealthCheck-UI.
213-
214209
Web API
215210

216211
`http://localhost:5000/health/ready`
217212

218-
![Readiness](./.assets/img/Readiness.png)
213+
```json
214+
{
215+
"status": "Healthy",
216+
"totalDuration": "00:00:00.2344435",
217+
"entries": {
218+
"Sql Server (Ready)": {
219+
"data": {},
220+
"duration": "00:00:00.2251420",
221+
"status": "Healthy",
222+
"tags": [
223+
"ready"
224+
]
225+
}
226+
}
227+
}
228+
```
219229

220230
Web MVC
221231

@@ -234,8 +244,8 @@ public void Configure(IApplicationBuilder app)
234244
{
235245
endpoints.MapDumpConfig(
236246
pattern: "/dump-config",
237-
configInfo: (_configuration as IConfigurationRoot).GetDebugView(),
238-
isDevelopment: _env.IsDevelopment());
247+
configurationRoot: _configuration as IConfigurationRoot,
248+
isProduction: _env.IsProduction());
239249
});
240250
}
241251
```

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"sdk": {
3-
"version": "6.0.100-preview.2.21155.3"
3+
"version": "6.0.100-preview.4.21255.9"
44
}
55
}

src/Dotnet6.GraphQL4.Repositories.Abstractions/DependencyInjection/Extensions/ServiceCollectionExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ public static OptionsBuilder<TransactionOptions> ConfigureTransactionOptions(thi
2525
=> services
2626
.AddOptions<TransactionOptions>()
2727
.Bind(section)
28+
.ValidateDataAnnotations()
2829
.Validate(
2930
validation: options => options.IsolationLevel is not System.Transactions.IsolationLevel.Unspecified,
30-
failureMessage: "Transaction isolation level must be specified");
31+
failureMessage: "Transaction isolation level must be specified")
32+
.ValidateOnStart();
3133
}
3234
}
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
using System.Transactions;
1+
using System.ComponentModel.DataAnnotations;
2+
using System.Transactions;
23

34
namespace Dotnet6.GraphQL4.Repositories.Abstractions.DependencyInjection.Options
45
{
56
public class TransactionOptions
67
{
7-
private const IsolationLevel DefaultIsolationLevel = IsolationLevel.ReadCommitted;
8-
private IsolationLevel? _isolationLevel;
9-
10-
public IsolationLevel IsolationLevel
11-
{
12-
get => _isolationLevel ?? DefaultIsolationLevel;
13-
set => _isolationLevel = value;
14-
}
8+
[Required, EnumDataType(typeof(IsolationLevel))]
9+
public IsolationLevel IsolationLevel { get; set; }
1510
}
1611
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2+
23
<ItemGroup>
34
<PackageReference Include="AutoMapper" Version="$(AutoMapper_Version)" />
45
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="$(Microsoft_EntityFrameworkCore_Version)" />
56
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="$(Microsoft_Extensions_Version)" />
67
<PackageReference Include="Scrutor" Version="$(Scrutor_Version)" />
8+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="$(Microsoft_Extensions_Version)" />
9+
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="$(Microsoft_Extensions_Version)" />
710
</ItemGroup>
11+
812
<ItemGroup>
913
<ProjectReference Include="..\Dotnet6.GraphQL4.Domain.Abstractions\Dotnet6.GraphQL4.Domain.Abstractions.csproj" />
1014
</ItemGroup>
15+
1116
</Project>

src/Dotnet6.GraphQL4.Repositories.Abstractions/UnitsOfWork/UnitOfWork.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ public class UnitOfWork : IUnitOfWork
2020

2121
public UnitOfWork(
2222
DbContext dbContext,
23-
IOptionsSnapshot<TransactionOptions> optionsMonitor,
23+
IOptionsSnapshot<TransactionOptions> optionsSnapshot,
2424
INotificationContext notificationContext)
2525
{
2626
_dbContext = dbContext;
27-
_options = optionsMonitor.Value;
27+
_options = optionsSnapshot.Value;
2828
_database = _dbContext.Database;
2929
_notificationContext = notificationContext;
3030
}

src/Dotnet6.GraphQL4.Store.Repositories/Configurations/Products/BackpackConfiguration.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ public void Configure(EntityTypeBuilder<Backpack> builder)
1616

1717
builder
1818
.Property(x => x.BackpackType)
19-
.HasConversion(new EnumToStringConverter<BackpackType>());
19+
.HasConversion(new EnumToStringConverter<BackpackType>())
20+
.IsUnicode(false)
21+
.HasMaxLength(30);
2022
}
2123
}
2224
}

src/Dotnet6.GraphQL4.Store.Repositories/Configurations/Products/BootConfiguration.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ public void Configure(EntityTypeBuilder<Boot> builder)
1919

2020
builder
2121
.Property(x => x.BootType)
22-
.HasConversion(new EnumToStringConverter<BootType>());
22+
.HasConversion(new EnumToStringConverter<BootType>())
23+
.IsUnicode(false)
24+
.HasMaxLength(30);
2325
}
2426
}
2527
}

src/Dotnet6.GraphQL4.Store.Repositories/Configurations/Products/KayakConfiguration.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ public void Configure(EntityTypeBuilder<Kayak> builder)
1616

1717
builder
1818
.Property(x => x.KayakType)
19-
.HasConversion(new EnumToStringConverter<KayakType>());
19+
.HasConversion(new EnumToStringConverter<KayakType>())
20+
.IsUnicode(false)
21+
.HasMaxLength(30);
2022

2123
builder
2224
.Property(x => x.AmountOfPerson);

src/Dotnet6.GraphQL4.Store.Repositories/Configurations/Products/ProductConfiguration.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,21 @@ public void Configure(EntityTypeBuilder<Product> builder)
2020

2121
builder
2222
.Property(x => x.Description)
23+
.IsUnicode(false)
2324
.HasMaxLength(300);
2425

2526
builder
2627
.Property(x => x.IntroduceAt);
2728

2829
builder
2930
.Property(x => x.Name)
31+
.IsUnicode(false)
3032
.HasMaxLength(50)
3133
.IsRequired();
3234

3335
builder
3436
.Property(x => x.PhotoUrl)
37+
.IsUnicode(false)
3538
.HasMaxLength(100);
3639

3740
builder
@@ -41,7 +44,9 @@ public void Configure(EntityTypeBuilder<Product> builder)
4144

4245
builder
4346
.Property(x => x.Option)
44-
.HasConversion(new EnumToStringConverter<Option>());
47+
.HasConversion(new EnumToStringConverter<Option>())
48+
.IsUnicode(false)
49+
.HasMaxLength(30);
4550

4651
builder
4752
.Property(x => x.Rating);
@@ -65,6 +70,7 @@ public void Configure(EntityTypeBuilder<Product> builder)
6570

6671
builder
6772
.Property(DiscriminatorDefaultName)
73+
.IsUnicode(false)
6874
.HasMaxLength(30);
6975
}
7076
}

src/Dotnet6.GraphQL4.Store.Repositories/Configurations/Reviews/ReviewConfiguration.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ public void Configure(EntityTypeBuilder<Review> builder)
1212
.HasKey(x => x.Id);
1313

1414
builder
15-
.Property(x => x.Comment);
15+
.Property(x => x.Comment)
16+
.IsUnicode(false)
17+
.HasMaxLength(1000);
1618

1719
builder
1820
.Property(x => x.Title)
21+
.IsUnicode(false)
1922
.HasMaxLength(100);
2023

2124
builder

src/Dotnet6.GraphQL4.Store.Repositories/DependencyInjection/Extensions/ServiceCollectionExtensions.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
using Microsoft.EntityFrameworkCore;
44
using Microsoft.Extensions.Configuration;
55
using Microsoft.Extensions.DependencyInjection;
6+
using Microsoft.Extensions.Diagnostics.HealthChecks;
67
using Microsoft.Extensions.Options;
78

89
namespace Dotnet6.GraphQL4.Store.Repositories.DependencyInjection.Extensions
910
{
1011
public static class ServiceCollectionExtensions
1112
{
13+
private static readonly string[] ReadinessTags = {"ready"};
14+
private static readonly string[] LivenessTags = {"live"};
15+
1216
public static IServiceCollection AddApplicationDbContext(this IServiceCollection services)
1317
=> services
1418
.AddScoped<DbContext, StoreDbContext>()
@@ -18,8 +22,20 @@ public static OptionsBuilder<SqlServerRetryingOptions> ConfigureSqlServerRetryin
1822
=> services
1923
.AddOptions<SqlServerRetryingOptions>()
2024
.Bind(section)
21-
.Validate(
22-
validation: options => options.MaxRetryCount <= 10 || options.MaxSecondsRetryDelay <= 10,
23-
failureMessage: "Max value for Retry or Delay must be 10.");
25+
.ValidateDataAnnotations()
26+
.ValidateOnStart();
27+
28+
public static IHealthChecksBuilder AddDbContextHealthChecks(this IServiceCollection services)
29+
=> services.AddHealthChecks()
30+
.AddDbContextCheck<DbContext>(
31+
name: "Sql Server (Live)",
32+
failureStatus: HealthStatus.Degraded,
33+
tags: LivenessTags)
34+
.AddDbContextCheck<StoreDbContext>(
35+
name: "Sql Server (Ready)",
36+
failureStatus: HealthStatus.Unhealthy,
37+
tags: ReadinessTags,
38+
customTestQuery: (dbContext, cancellationToken)
39+
=> dbContext.Products.AnyAsync(cancellationToken));
2440
}
2541
}
Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,19 @@
11
using System;
2+
using System.ComponentModel.DataAnnotations;
23

34
namespace Dotnet6.GraphQL4.Store.Repositories.DependencyInjection.Options
45
{
56
public class SqlServerRetryingOptions
67
{
7-
private const int DefaultRetryCount = 5;
8-
private const int DefaultRetryDelay = 5;
8+
[Required, Range(5, 20)]
9+
public int MaxRetryCount { get; init; }
910

10-
private int _maxRetryCount;
11-
private int _maxSecondsRetryDelay;
11+
[Required, Range(5, 20)]
12+
public int MaxSecondsRetryDelay { get; init; }
1213

13-
public int MaxRetryCount
14-
{
15-
get => _maxRetryCount <= 0 ? DefaultRetryCount : _maxRetryCount;
16-
set => _maxRetryCount = value;
17-
}
14+
public int[] ErrorNumbersToAdd { get; init; }
1815

19-
public int MaxSecondsRetryDelay
20-
{
21-
get => _maxSecondsRetryDelay <= 0 ? DefaultRetryDelay : _maxSecondsRetryDelay;
22-
set => _maxSecondsRetryDelay = value;
23-
}
24-
25-
public int[] ErrorNumbersToAdd { get; set; }
26-
27-
internal TimeSpan MaxRetryDelay
16+
internal TimeSpan MaxRetryDelay
2817
=> TimeSpan.FromSeconds(MaxSecondsRetryDelay);
2918
}
3019
}

0 commit comments

Comments
 (0)