Skip to content

Commit 33b01a2

Browse files
committed
.Net 7
1 parent ff3f4d3 commit 33b01a2

File tree

13 files changed

+100
-52
lines changed

13 files changed

+100
-52
lines changed

Diff for: Source/Lib/Directory.Build.props

+4-4
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 />
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+
}

Diff for: Source/Lib/Morris.Blazor.FluentValidation/FluentValidationValidatorProvider.cs

+7-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using Microsoft.AspNetCore.Components.Forms;
55
using Morris.Blazor.Validation;
66
using System;
7-
using System.Collections;
87
using System.Collections.Generic;
98
using System.Linq;
109
using System.Reflection;
@@ -16,18 +15,20 @@ 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('[');

Diff for: Source/Lib/Morris.Blazor.FluentValidation/Morris.Blazor.FluentValidation.csproj

+9-5
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" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<PackageReference Include="FluentValidation" Version="11.4.0" />
1216
</ItemGroup>
1317

1418
<ItemGroup>
1519
<ProjectReference Include="..\Morris.Blazor.Validation\Morris.Blazor.Validation.csproj" />
1620
</ItemGroup>
1721

1822
<ItemGroup>
19-
<None Include="blazor-fluentvalidation.png">
20-
<Pack>True</Pack>
21-
<PackagePath></PackagePath>
22-
</None>
23+
<None Include="blazor-fluentvalidation.png">
24+
<Pack>True</Pack>
25+
<PackagePath></PackagePath>
26+
</None>
2327
</ItemGroup>
2428

2529
</Project>

Diff for: Source/Lib/Morris.Blazor.Validation/DataAnnotationsValidatorProvider.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ 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
}

Diff for: Source/Lib/Morris.Blazor.Validation/Extensions/EditContextExtensions.cs

+2-10
Original file line numberDiff line numberDiff line change
@@ -115,24 +115,16 @@ private static void NotifyPropertyChanged(
115115
IsModifiedProperty.SetValue(fieldState, originalIsModified);
116116
}
117117

118-
private static Object GetFieldState(EditContext editContext, FieldIdentifier fieldIdentifier)
118+
private static object GetFieldState(EditContext editContext, FieldIdentifier fieldIdentifier)
119119
{
120-
#if (NETSTANDARD2_0 || NETSTANDARD2_1)
121-
Object[] parameters = new object[] { fieldIdentifier, true };
122-
#elif (NET5_0_OR_GREATER)
123-
Object[] parameters = new object[] { fieldIdentifier };
124-
#endif
120+
var parameters = new object[] { fieldIdentifier };
125121
EnsureGetFieldStateMethod(editContext);
126122
return GetFieldStateMethod.Invoke(editContext, parameters);
127123
}
128124

129125
private static void EnsureGetFieldStateMethod(EditContext editContext)
130126
{
131-
#if (NETSTANDARD2_0 || NETSTANDARD2_1)
132-
var methodname = "GetFieldState";
133-
#elif (NET5_0_OR_GREATER)
134127
var methodname = "GetOrAddFieldState";
135-
#endif
136128

137129
if (GetFieldStateMethod == null)
138130
{

Diff for: Source/Lib/Morris.Blazor.Validation/IValidationProvider.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ namespace Morris.Blazor.Validation
55
{
66
public interface IValidationProvider
77
{
8-
void InitializeEditContext(EditContext editContext, IServiceProvider serviceProvider);
8+
void InitializeEditContext(EditContext editContext, IServiceProvider serviceProvider, ValidationProperties properties);
99
}
1010
}

Diff for: Source/Lib/Morris.Blazor.Validation/Morris.Blazor.Validation.csproj

+9-12
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,20 @@
1212
<PackageIcon>blazor-validation.png</PackageIcon>
1313
</PropertyGroup>
1414

15-
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
16-
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.3" />
17-
</ItemGroup>
18-
19-
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
20-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.0" />
15+
<ItemGroup>
16+
<SupportedPlatform Include="browser" />
2117
</ItemGroup>
2218

23-
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
24-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.0" />
19+
<ItemGroup>
20+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.0" Condition="'$(TargetFramework)' == 'net7.0'"/>
21+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.0" Condition="'$(TargetFramework)' == 'net6.0'"/>
2522
</ItemGroup>
2623

2724
<ItemGroup>
28-
<None Include="blazor-validation.png">
29-
<Pack>True</Pack>
30-
<PackagePath></PackagePath>
31-
</None>
25+
<None Include="blazor-validation.png">
26+
<Pack>True</Pack>
27+
<PackagePath></PackagePath>
28+
</None>
3229
</ItemGroup>
3330

3431
</Project>

Diff for: Source/Lib/Morris.Blazor.Validation/Validate.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ public class Validate : ComponentBase
1313
[Inject]
1414
IValidationProviderRepository Repository { get; set; }
1515

16+
[Parameter]
17+
public ValidationProperties ValidationProperties { get; set; }
18+
1619
[Inject]
1720
IServiceProvider ServiceProvider { get; set; }
1821

@@ -36,7 +39,7 @@ private void EditContextChanged()
3639
foreach (Type providerType in Repository.All)
3740
{
3841
var validationProvider = (IValidationProvider)ServiceProvider.GetService(providerType);
39-
validationProvider.InitializeEditContext(CurrentEditContext, ServiceProvider);
42+
validationProvider.InitializeEditContext(CurrentEditContext, ServiceProvider, ValidationProperties);
4043
}
4144
}
4245
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Collections.ObjectModel;
4+
5+
namespace Morris.Blazor.Validation
6+
{
7+
public class ValidationProperties
8+
{
9+
private readonly Dictionary<string, object> MutableValues = new Dictionary<string, object>();
10+
11+
public readonly IReadOnlyDictionary<string, object> Values;
12+
13+
private ValidationProperties()
14+
{
15+
Values = new ReadOnlyDictionary<string, object>(MutableValues);
16+
}
17+
18+
public static ValidationProperties Set => new ValidationProperties();
19+
20+
public ValidationProperties Value(string name, object value)
21+
{
22+
if (string.IsNullOrWhiteSpace(name))
23+
throw new ArgumentException(message: "Required", paramName: nameof(name));
24+
if (value is null)
25+
throw new ArgumentNullException(nameof(value));
26+
27+
MutableValues.Add(name, value);
28+
return this;
29+
}
30+
}
31+
32+
}

Diff for: Source/Samples/01-DataAnnotationsValidation/DataAnnotationsValidationSample/DataAnnotationsValidationSample.csproj

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.1</TargetFramework>
5-
<RazorLangVersion>3.0</RazorLangVersion>
4+
<TargetFramework>net7.0</TargetFramework>
65
</PropertyGroup>
76

87
<ItemGroup>
9-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.1" />
10-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.1" PrivateAssets="all" />
11-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.1" PrivateAssets="all" />
8+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.1" />
9+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.1" PrivateAssets="all" />
1210
</ItemGroup>
1311

1412
<ItemGroup>
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net7.0</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<ProjectReference Include="..\..\..\Lib\Morris.Blazor.FluentValidation\Morris.Blazor.FluentValidation.csproj" />
9-
<ProjectReference Include="..\..\..\Lib\Morris.Blazor.Validation\Morris.Blazor.Validation.csproj" />
8+
<ProjectReference Include="..\..\..\Lib\Morris.Blazor.FluentValidation\Morris.Blazor.FluentValidation.csproj" />
9+
<ProjectReference Include="..\..\..\Lib\Morris.Blazor.Validation\Morris.Blazor.Validation.csproj" />
1010
</ItemGroup>
1111

1212
</Project>

Diff for: Source/Samples/02-FluentValidation/FluentValidationSample/Pages/Index.razor

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
@page "/"
2+
@using FluentValidationSample.FluentValidators
3+
@using Morris.Blazor.Validation
24
@using Morris.Blazor.Validation.Extensions
5+
@using Morris.Blazor.FluentValidation
36

47
<EditForm Model=@Person OnSubmit=SubmitForm>
5-
<Morris.Blazor.Validation.Validate />
8+
<Morris.Blazor.Validation.Validate ValidationProperties=@(ValidationProperties.Set.FluentValidator<PersonValidator>())/>
69
<div class="mb-2 row">
710
<div class="col-3">
811
<label>Salutation</label>

0 commit comments

Comments
 (0)