Skip to content
This repository was archived by the owner on Dec 11, 2020. It is now read-only.

Commit 5df2b12

Browse files
Added default conventions
1 parent 5804117 commit 5df2b12

7 files changed

Lines changed: 131 additions & 28 deletions

AspNetCore.Extensions.sln

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rocket.Surgery.AspNetCore",
2323
EndProject
2424
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rocket.Surgery.AspNetCore.Tests", "test\AspNetCore.Tests\Rocket.Surgery.AspNetCore.Tests.csproj", "{66F293DB-9507-40E0-B1FA-5CDAA0088364}"
2525
EndProject
26+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rocket.Surgery.AspNetCore.NewtonsoftJson", "src\AspNetCore.NewtonsoftJson\Rocket.Surgery.AspNetCore.NewtonsoftJson.csproj", "{60552C08-A164-4BB5-BE5C-62110D997D74}"
27+
EndProject
2628
Global
2729
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2830
Debug|Any CPU = Debug|Any CPU
@@ -67,6 +69,18 @@ Global
6769
{66F293DB-9507-40E0-B1FA-5CDAA0088364}.Release|x64.Build.0 = Release|Any CPU
6870
{66F293DB-9507-40E0-B1FA-5CDAA0088364}.Release|x86.ActiveCfg = Release|Any CPU
6971
{66F293DB-9507-40E0-B1FA-5CDAA0088364}.Release|x86.Build.0 = Release|Any CPU
72+
{60552C08-A164-4BB5-BE5C-62110D997D74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
73+
{60552C08-A164-4BB5-BE5C-62110D997D74}.Debug|Any CPU.Build.0 = Debug|Any CPU
74+
{60552C08-A164-4BB5-BE5C-62110D997D74}.Debug|x64.ActiveCfg = Debug|Any CPU
75+
{60552C08-A164-4BB5-BE5C-62110D997D74}.Debug|x64.Build.0 = Debug|Any CPU
76+
{60552C08-A164-4BB5-BE5C-62110D997D74}.Debug|x86.ActiveCfg = Debug|Any CPU
77+
{60552C08-A164-4BB5-BE5C-62110D997D74}.Debug|x86.Build.0 = Debug|Any CPU
78+
{60552C08-A164-4BB5-BE5C-62110D997D74}.Release|Any CPU.ActiveCfg = Release|Any CPU
79+
{60552C08-A164-4BB5-BE5C-62110D997D74}.Release|Any CPU.Build.0 = Release|Any CPU
80+
{60552C08-A164-4BB5-BE5C-62110D997D74}.Release|x64.ActiveCfg = Release|Any CPU
81+
{60552C08-A164-4BB5-BE5C-62110D997D74}.Release|x64.Build.0 = Release|Any CPU
82+
{60552C08-A164-4BB5-BE5C-62110D997D74}.Release|x86.ActiveCfg = Release|Any CPU
83+
{60552C08-A164-4BB5-BE5C-62110D997D74}.Release|x86.Build.0 = Release|Any CPU
7084
EndGlobalSection
7185
GlobalSection(SolutionProperties) = preSolution
7286
HideSolutionNode = FALSE
@@ -75,6 +89,7 @@ Global
7589
{55EFAE2F-A7CA-4917-A381-4A6EF5E79610} = {E3DCB78E-EE06-4EA3-88AC-762D8910387C}
7690
{5C494CDA-7522-45F1-95B5-A991F596FC67} = {8FFDF555-DB50-45F9-9A2D-6410F39151C3}
7791
{66F293DB-9507-40E0-B1FA-5CDAA0088364} = {DF33E0FB-9790-4654-B60F-8AB22E0CC3D1}
92+
{60552C08-A164-4BB5-BE5C-62110D997D74} = {8FFDF555-DB50-45F9-9A2D-6410F39151C3}
7893
EndGlobalSection
7994
GlobalSection(ExtensibilityGlobals) = postSolution
8095
SolutionGuid = {439897C2-CCBD-44FE-B2DC-A3E4670ADA59}

Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<PackageReference Update="Rocket.Surgery.Build.Information" Version="3.3.11" />
2828
<PackageReference Update="NodaTime" Version="2.4.7" />
2929
<PackageReference Update="NodaTime.Serialization.JsonNet" Version="2.2.0" />
30+
<PackageReference Update="NodaTime.Serialization.SystemTextJson" Version="1.0.0-beta01" />
3031
</ItemGroup>
3132
<ItemGroup>
3233
<PackageReference Update="Rocket.Surgery.Extensions.Testing.FakeItEasy" Version="3.3.0" />
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.IO;
3+
using System.Linq;
4+
using System.Text.Json;
5+
using System.Xml.XPath;
6+
using JetBrains.Annotations;
7+
using Microsoft.AspNetCore.Mvc;
8+
using Microsoft.Extensions.DependencyInjection;
9+
using NodaTime;
10+
using NodaTime.Serialization.SystemTextJson;
11+
using Rocket.Surgery.AspNetCore;
12+
using Rocket.Surgery.Conventions;
13+
using Rocket.Surgery.Extensions.DependencyInjection;
14+
using Newtonsoft.Json.Converters;
15+
using Newtonsoft.Json.Serialization;
16+
using NodaTime.Serialization.JsonNet;
17+
18+
[assembly: Convention(typeof(NewtonsoftJsonConvention))]
19+
20+
namespace Rocket.Surgery.AspNetCore
21+
{
22+
/// <summary>
23+
/// ValidationConvention.
24+
/// Implements the <see cref="IServiceConvention" />
25+
/// </summary>
26+
/// <seealso cref="IServiceConvention" />
27+
/// <seealso cref="IServiceConvention" />
28+
[PublicAPI]
29+
public class NewtonsoftJsonConvention : IServiceConvention
30+
{
31+
/// <summary>
32+
/// Registers the specified context.
33+
/// </summary>
34+
/// <param name="context">The context.</param>
35+
public void Register(IServiceConventionContext context)
36+
{
37+
if (context is null)
38+
{
39+
throw new ArgumentNullException(nameof(context));
40+
}
41+
42+
context.Services.Configure<MvcNewtonsoftJsonOptions>(
43+
options =>
44+
{
45+
options.SerializerSettings.Converters.Add(new StringEnumConverter(new CamelCaseNamingStrategy()));
46+
options.SerializerSettings
47+
.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);
48+
}
49+
);
50+
}
51+
}
52+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
4+
<PackageDescription>Provides feature folders via convention to a Rocket Surgery Web Application</PackageDescription>
5+
<PackageTags>$(PackageTags);feature folders;feature</PackageTags>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<FrameworkReference Include="Microsoft.AspNetCore.App" />
9+
<PackageReference Include="NodaTime.Serialization.JsonNet" />
10+
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" />
11+
<ProjectReference Include="../AspNetCore/Rocket.Surgery.AspNetCore.csproj" />
12+
</ItemGroup>
13+
</Project>

src/AspNetCore/Filters/ValidationExceptionFilter.cs

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/AspNetCore/Rocket.Surgery.AspNetCore.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@
1212
<PackageReference Include="Rocket.Surgery.Conventions.Abstractions" />
1313
<PackageReference Include="Rocket.Surgery.Extensions.DependencyInjection.Abstractions" />
1414
<PackageReference Include="Rocket.Surgery.Extensions.Abstractions" />
15+
<PackageReference Include="NodaTime" />
16+
<PackageReference Include="NodaTime.Serialization.SystemTextJson" />
1517
</ItemGroup>
1618
</Project>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.IO;
3+
using System.Linq;
4+
using System.Text.Json;
5+
using System.Xml.XPath;
6+
using JetBrains.Annotations;
7+
using Microsoft.AspNetCore.Mvc;
8+
using Microsoft.Extensions.DependencyInjection;
9+
using NodaTime;
10+
using NodaTime.Serialization.SystemTextJson;
11+
using Rocket.Surgery.AspNetCore;
12+
using Rocket.Surgery.Conventions;
13+
using Rocket.Surgery.Extensions.DependencyInjection;
14+
15+
[assembly: Convention(typeof(SystemJsonTextConvention))]
16+
17+
namespace Rocket.Surgery.AspNetCore
18+
{
19+
/// <summary>
20+
/// ValidationConvention.
21+
/// Implements the <see cref="IServiceConvention" />
22+
/// </summary>
23+
/// <seealso cref="IServiceConvention" />
24+
/// <seealso cref="IServiceConvention" />
25+
[PublicAPI]
26+
public class SystemJsonTextConvention : IServiceConvention
27+
{
28+
/// <summary>
29+
/// Registers the specified context.
30+
/// </summary>
31+
/// <param name="context">The context.</param>
32+
public void Register(IServiceConventionContext context)
33+
{
34+
if (context is null)
35+
{
36+
throw new ArgumentNullException(nameof(context));
37+
}
38+
39+
context.Services.Configure<JsonOptions>(
40+
options =>
41+
{
42+
options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
43+
options.JsonSerializerOptions.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);
44+
}
45+
);
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)