Skip to content

Commit 24fb06b

Browse files
authored
Merge pull request #46 from mrpmorris/release/2.0
- Add support for .NET 7 - Drop unsupported frameworks
2 parents 38068ad + 33b01a2 commit 24fb06b

81 files changed

Lines changed: 180 additions & 130 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ Blazor-Validation is a validation agnostic library for validating forms in Blazo
77

88
## Installation
99
You can download the latest release / pre-release NuGet packages from the official NuGet pages:
10-
- [Blazor-Validation] [![NuGet version (PeterLeslieMorris.Blazor.Validation)](https://img.shields.io/nuget/v/PeterLeslieMorris.Blazor.Validation.svg?style=flat-square)](https://www.nuget.org/packages/PeterLeslieMorris.Blazor.Validation/)
11-
- [Blazor-FluentValidation] [![NuGet version (PeterLeslieMorris.Blazor.FluentValidation)](https://img.shields.io/nuget/v/PeterLeslieMorris.Blazor.FluentValidation.svg?style=flat-square)](https://www.nuget.org/packages/PeterLeslieMorris.Blazor.FluentValidation/)
10+
- [Blazor-Validation] [![NuGet version (Morris.Blazor.Validation)](https://img.shields.io/nuget/v/Morris.Blazor.Validation.svg?style=flat-square)](https://www.nuget.org/packages/Morris.Blazor.Validation/)
11+
- [Blazor-FluentValidation] [![NuGet version (Morris.Blazor.FluentValidation)](https://img.shields.io/nuget/v/Morris.Blazor.FluentValidation.svg?style=flat-square)](https://www.nuget.org/packages/Morris.Blazor.FluentValidation/)
1212

1313
## Getting started
14-
1. Add a reference to PeterLeslieMorris.Blazor.Validation
15-
2. Inside the `<EditForm>` in your razor files, add `<PeterLeslieMorris.Blazor.Validation.Validate/>`
16-
3. In startup.cs add `using PeterLeslieMorris.Blazor.Validation` and then add the relevant validation in the `ConfigureServices` method.
14+
1. Add a reference to Morris.Blazor.Validation
15+
2. Inside the `<EditForm>` in your razor files, add `<Morris.Blazor.Validation.Validate/>`
16+
3. In startup.cs add `using Morris.Blazor.Validation` and then add the relevant validation in the `ConfigureServices` method.
1717

1818
- `services.AddFormValidation(config => config.AddDataAnnotationsValidation());`
1919
- `services.AddFormValidation(config => config.AddFluentValidation(typeof(SomeValidator).Assembly));`
@@ -102,8 +102,8 @@ More sample projects will be added as the framework develops.
102102
- Initial public release
103103

104104
[Microsoft aspdotnet blazor project]: <https://github.com/aspnet/Blazor>
105-
[Blazor-Validation]: <https://www.nuget.org/packages/PeterLeslieMorris.Blazor.Validation/>
106-
[Blazor-FluentValidation]: <https://www.nuget.org/packages/PeterLeslieMorris.Blazor.FluentValidation/>
105+
[Blazor-Validation]: <https://www.nuget.org/packages/Morris.Blazor.Validation/>
106+
[Blazor-FluentValidation]: <https://www.nuget.org/packages/Morris.Blazor.FluentValidation/>
107107
[Data Annotations Sample]: <https://github.com/mrpmorris/blazor-validation/tree/master/samples/01-DataAnnotationsValidation/>
108108
[FluentValidation Sample]: <https://github.com/mrpmorris/blazor-validation/tree/master/samples/02-FluentValidation/>
109109
[Blazored FluentValidation]: <https://github.com/Blazored/FluentValidation>
File renamed without changes.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
<PropertyGroup>
44

5-
<Version>1.8.0</Version>
6-
<AssemblyVersion>1.8.0.0</AssemblyVersion>
7-
<FileVersion>1.8.0.0</FileVersion>
5+
<Version>2.0.0</Version>
6+
<AssemblyVersion>2.0.0.0</AssemblyVersion>
7+
<FileVersion>2.0.0.0</FileVersion>
88

99
<Authors>Peter Morris</Authors>
1010
<Company />
1111
<Copyright>Peter Morris</Copyright>
1212
<PackageLicenseFile></PackageLicenseFile>
1313
<PackageLicenseExpression>MIT</PackageLicenseExpression>
14-
<TargetFrameworks>netstandard2.1;net5.0;net6.0</TargetFrameworks>
14+
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
1515

1616
<PackageProjectUrl>https://github.com/mrpmorris/blazor-validation</PackageProjectUrl>
1717
<PackageIconUrl />
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using FluentValidation;
2+
using Morris.Blazor.Validation;
3+
4+
namespace Morris.Blazor.FluentValidation
5+
{
6+
public static class FluentValidationPropertiesExtensions
7+
{
8+
public const string FluentValidatorKey = "FluentValidatorKey";
9+
10+
public static ValidationProperties FluentValidator<T>(this ValidationProperties properties)
11+
where T : IValidator
12+
{
13+
return properties.Value("x", "y");
14+
}
15+
}
16+
}

src/PeterLeslieMorris.Blazor.FluentValidation/FluentValidationRepository.cs renamed to Source/Lib/Morris.Blazor.FluentValidation/FluentValidationRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Collections.ObjectModel;
44
using System.Linq;
55

6-
namespace PeterLeslieMorris.Blazor.FluentValidation
6+
namespace Morris.Blazor.FluentValidation
77
{
88
internal class FluentValidationRepository
99
{

src/PeterLeslieMorris.Blazor.FluentValidation/FluentValidationValidatorProvider.cs renamed to Source/Lib/Morris.Blazor.FluentValidation/FluentValidationValidatorProvider.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,33 @@
22
using FluentValidation.Internal;
33
using FluentValidation.Results;
44
using Microsoft.AspNetCore.Components.Forms;
5-
using PeterLeslieMorris.Blazor.Validation;
5+
using Morris.Blazor.Validation;
66
using System;
7-
using System.Collections;
87
using System.Collections.Generic;
98
using System.Linq;
109
using System.Reflection;
1110
using System.Threading.Tasks;
1211

13-
namespace PeterLeslieMorris.Blazor.FluentValidation
12+
namespace Morris.Blazor.FluentValidation
1413
{
1514
public class FluentValidationValidatorProvider : IValidationProvider
1615
{
1716
public void InitializeEditContext(
1817
EditContext editContext,
19-
IServiceProvider serviceProvider)
18+
IServiceProvider serviceProvider,
19+
ValidationProperties properties)
2020
{
2121
if (editContext == null)
2222
throw new ArgumentNullException(nameof(editContext));
2323
if (serviceProvider == null)
2424
throw new ArgumentNullException(nameof(serviceProvider));
25+
properties ??= ValidationProperties.Set;
2526

2627
var messages = new ValidationMessageStore(editContext);
2728
editContext.OnValidationRequested +=
2829
(sender, eventArgs) =>
2930
{
30-
_ = ValidateModel((EditContext)sender, messages, serviceProvider);
31+
_ = ValidateModel((EditContext)sender, messages, serviceProvider, properties);
3132
};
3233

3334
editContext.OnFieldChanged +=
@@ -40,7 +41,8 @@ public void InitializeEditContext(
4041
private async Task ValidateModel(
4142
EditContext editContext,
4243
ValidationMessageStore messages,
43-
IServiceProvider serviceProvider)
44+
IServiceProvider serviceProvider,
45+
ValidationProperties properties)
4446
{
4547
if (editContext == null)
4648
throw new ArgumentNullException(nameof(editContext));
@@ -89,7 +91,7 @@ private void GetParentObjectAndPropertyName(
8991
Type modelType = model.GetType();
9092
while (propertyPathParts.Count > 1)
9193
{
92-
var name = propertyPathParts.Dequeue();
94+
string name = propertyPathParts.Dequeue();
9395

9496
string propertyIndexString = null;
9597
int bracketIndex = name.IndexOf('[');

src/PeterLeslieMorris.Blazor.FluentValidation/PeterLeslieMorris.Blazor.FluentValidation.csproj renamed to Source/Lib/Morris.Blazor.FluentValidation/Morris.Blazor.FluentValidation.csproj

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,22 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="FluentValidation" Version="11.0.0" />
11+
<SupportedPlatform Include="browser" />
1212
</ItemGroup>
1313

1414
<ItemGroup>
15-
<ProjectReference Include="..\PeterLeslieMorris.Blazor.Validation\PeterLeslieMorris.Blazor.Validation.csproj" />
15+
<PackageReference Include="FluentValidation" Version="11.4.0" />
1616
</ItemGroup>
1717

1818
<ItemGroup>
19-
<None Include="blazor-fluentvalidation.png">
20-
<Pack>True</Pack>
21-
<PackagePath></PackagePath>
22-
</None>
19+
<ProjectReference Include="..\Morris.Blazor.Validation\Morris.Blazor.Validation.csproj" />
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<None Include="blazor-fluentvalidation.png">
24+
<Pack>True</Pack>
25+
<PackagePath></PackagePath>
26+
</None>
2327
</ItemGroup>
2428

2529
</Project>

src/PeterLeslieMorris.Blazor.FluentValidation/ValidationConfigurationFluentValidationExtensions.cs renamed to Source/Lib/Morris.Blazor.FluentValidation/ValidationConfigurationFluentValidationExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
using FluentValidation;
22
using Microsoft.Extensions.DependencyInjection;
33
using Microsoft.Extensions.DependencyInjection.Extensions;
4-
using PeterLeslieMorris.Blazor.FluentValidation;
4+
using Morris.Blazor.FluentValidation;
55
using System;
66
using System.Collections.Generic;
77
using System.Linq;
88
using System.Reflection;
99

10-
namespace PeterLeslieMorris.Blazor.Validation
10+
namespace Morris.Blazor.Validation
1111
{
1212
public static class ValidationConfigurationFluentValidationExtensions
1313
{

src/PeterLeslieMorris.Blazor.FluentValidation/blazor-fluentvalidation.png renamed to Source/Lib/Morris.Blazor.FluentValidation/blazor-fluentvalidation.png

File renamed without changes.

src/PeterLeslieMorris.Blazor.Validation/DataAnnotationsValidatorProvider.cs renamed to Source/Lib/Morris.Blazor.Validation/DataAnnotationsValidatorProvider.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22
using Microsoft.Extensions.DependencyInjection;
33
using System;
44

5-
namespace PeterLeslieMorris.Blazor.Validation
5+
namespace Morris.Blazor.Validation
66
{
77
public class DataAnnotationsValidatorProvider : IValidationProvider
88
{
99
public void InitializeEditContext(
1010
EditContext editContext,
11-
IServiceProvider serviceProvider)
11+
IServiceProvider serviceProvider,
12+
ValidationProperties properties)
1213
{
13-
#if NET6_0_OR_GREATER
14-
editContext.EnableDataAnnotationsValidation();
14+
#if NET7_0_OR_GREATER
15+
editContext.EnableDataAnnotationsValidation(serviceProvider);
1516
#else
16-
editContext.AddDataAnnotationsValidation();
17+
editContext.EnableDataAnnotationsValidation();
1718
#endif
1819
}
1920
}

0 commit comments

Comments
 (0)