Skip to content

Commit 5055db0

Browse files
committed
UPdate readme for 1.4.0
1 parent dd876a4 commit 5055db0

File tree

9 files changed

+54
-21
lines changed

9 files changed

+54
-21
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ More sample projects will be added as the framework develops.
3333
- [FluentValidation Sample]- Shows how to use the [FluentValidation.com] library to validate.
3434

3535
## What's new
36+
### New in 1.4.0
37+
- Upgrade to FluentValidation 9
38+
3639
### New in 1.3.0
3740
- Add new EditContext.ValidateProperties for validating sub-sets of an object
3841

samples/02-FluentValidation/FluentValidationSample/FluentValidators/PersonValidator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ public PersonValidator()
1313
RuleFor(x => x.Salutation)
1414
.Cascade(CascadeMode.StopOnFirstFailure)
1515
.NotEmpty()
16-
.MustAsync(UpdateUIOnError).WithMessage("Cannot be DR");
16+
.MustAsync(LongRunningAsyncMethod).WithMessage("Cannot be DR");
1717
RuleFor(x => x.GivenName).NotEmpty();
1818
RuleFor(x => x.FamilyName).NotEmpty();
1919
RuleFor(x => x.EmailAddress).NotEmpty().EmailAddress();
2020
RuleFor(x => x.Addresses).NotEmpty().WithMessage("At least one address is required");
2121
}
2222

23-
private async Task<bool> UpdateUIOnError(string arg1, CancellationToken arg2)
23+
private async Task<bool> LongRunningAsyncMethod(string arg1, CancellationToken arg2)
2424
{
25-
await Task.Delay(2000);
26-
if (string.Compare(arg1, "DR", StringComparison.InvariantCultureIgnoreCase) == 0)
25+
await Task.Delay(1000);
26+
if ("DR".Equals(arg1, StringComparison.InvariantCultureIgnoreCase))
2727
return false;
2828
return true;
2929
}

src/PeterLeslieMorris.Blazor.FluentValidation/FuentValidationValidatorProvider.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
using System;
77
using System.Collections.Generic;
88
using System.Linq;
9+
using System.Threading.Tasks;
910

1011
namespace PeterLeslieMorris.Blazor.FluentValidation
1112
{
1213
public class FluentValidationValidatorProvider : IValidationProvider
1314
{
14-
public void InitializeEditContext(EditContext editContext, IServiceProvider serviceProvider)
15+
public void InitializeEditContext(
16+
EditContext editContext,
17+
IServiceProvider serviceProvider)
1518
{
1619
if (editContext == null)
1720
throw new ArgumentNullException(nameof(editContext));
@@ -20,13 +23,22 @@ public void InitializeEditContext(EditContext editContext, IServiceProvider serv
2023

2124
var messages = new ValidationMessageStore(editContext);
2225
editContext.OnValidationRequested +=
23-
(sender, _) => ValidateModel((EditContext)sender, messages, serviceProvider);
26+
(sender, eventArgs) =>
27+
{
28+
_ = ValidateModel((EditContext)sender, messages, serviceProvider);
29+
};
2430

2531
editContext.OnFieldChanged +=
26-
(sender, eventArgs) => ValidateField(editContext, messages, eventArgs.FieldIdentifier, serviceProvider);
32+
(sender, eventArgs) =>
33+
{
34+
_ = ValidateField(editContext, messages, eventArgs.FieldIdentifier, serviceProvider);
35+
};
2736
}
2837

29-
private async void ValidateModel(EditContext editContext, ValidationMessageStore messages, IServiceProvider serviceProvider)
38+
private async Task ValidateModel(
39+
EditContext editContext,
40+
ValidationMessageStore messages,
41+
IServiceProvider serviceProvider)
3042
{
3143
if (editContext == null)
3244
throw new ArgumentNullException(nameof(editContext));
@@ -58,7 +70,7 @@ private async void ValidateModel(EditContext editContext, ValidationMessageStore
5870
editContext.NotifyValidationStateChanged();
5971
}
6072

61-
private async void ValidateField(
73+
private async Task ValidateField(
6274
EditContext editContext,
6375
ValidationMessageStore messages,
6476
FieldIdentifier fieldIdentifier,
@@ -105,7 +117,9 @@ private async void ValidateField(
105117
editContext.NotifyValidationStateChanged();
106118
}
107119

108-
private static IEnumerable<IValidator> GetValidatorsForObject(object model, IServiceProvider serviceProvider)
120+
private static IEnumerable<IValidator> GetValidatorsForObject(
121+
object model,
122+
IServiceProvider serviceProvider)
109123
{
110124
var validatorTypesRepository = (FluentValidationRepository)serviceProvider.GetService(typeof(FluentValidationRepository));
111125
IEnumerable<Type> validatorTypes = validatorTypesRepository.GetValidatorTypesForObject(model);

src/PeterLeslieMorris.Blazor.Validation/DataAnnotationsValidatorProvider.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@ namespace PeterLeslieMorris.Blazor.Validation
66
{
77
public class DataAnnotationsValidatorProvider : IValidationProvider
88
{
9-
public void InitializeEditContext(EditContext editContext, IServiceProvider serviceProvider)
9+
public void InitializeEditContext(
10+
EditContext editContext,
11+
IServiceProvider serviceProvider)
1012
{
1113
editContext.AddDataAnnotationsValidation();
1214
}
1315
}
1416

1517
public static class ValidationConfigurationDataAnnotationsExtensions
1618
{
17-
public static ValidationConfiguration AddDataAnnotationsValidation(this ValidationConfiguration config)
19+
public static ValidationConfiguration AddDataAnnotationsValidation(
20+
this ValidationConfiguration config)
1821
{
1922
config.Services.AddScoped<DataAnnotationsValidatorProvider>();
2023
config.Repository.Add(typeof(DataAnnotationsValidatorProvider));

src/PeterLeslieMorris.Blazor.Validation/Extensions/EditContextExtensions.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ public static bool ValidateObjectTree(this EditContext editContext)
2525
return !editContext.GetValidationMessages().Any();
2626
}
2727

28-
public static bool ValidateProperty(this EditContext editContext, FieldIdentifier fieldIdentifier)
28+
public static bool ValidateProperty(
29+
this EditContext editContext,
30+
FieldIdentifier fieldIdentifier)
2931
{
3032
if (fieldIdentifier.Model == null)
3133
return false;
@@ -40,7 +42,9 @@ public static bool ValidateProperty(this EditContext editContext, FieldIdentifie
4042
return !editContext.GetValidationMessages(fieldIdentifier).Any();
4143
}
4244

43-
public static bool ValidateProperties(this EditContext editContext, params FieldIdentifier[] properties)
45+
public static bool ValidateProperties(
46+
this EditContext editContext,
47+
params FieldIdentifier[] properties)
4448
{
4549
if (properties == null || properties.Length == 0)
4650
throw new ArgumentNullException(nameof(properties));
@@ -117,6 +121,5 @@ private static void NotifyPropertyChanged(
117121
editContext.NotifyFieldChanged(fieldIdentifier);
118122
IsModifiedProperty.SetValue(fieldState, originalIsModified);
119123
}
120-
121124
}
122125
}

src/PeterLeslieMorris.Blazor.Validation/Validate.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@ namespace PeterLeslieMorris.Blazor.Validation
77
{
88
public class Validate : ComponentBase
99
{
10-
[CascadingParameter] EditContext CurrentEditContext { get; set; }
11-
[Inject] IValidationProviderRepository Repository { get; set; }
12-
[Inject] IServiceProvider ServiceProvider { get; set; }
10+
[CascadingParameter]
11+
EditContext CurrentEditContext { get; set; }
12+
13+
[Inject]
14+
IValidationProviderRepository Repository { get; set; }
15+
16+
[Inject]
17+
IServiceProvider ServiceProvider { get; set; }
1318

1419
public override async Task SetParametersAsync(ParameterView parameters)
1520
{

src/PeterLeslieMorris.Blazor.Validation/ValidationConfiguration.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ public class ValidationConfiguration
88
public IServiceCollection Services { get; }
99
public IValidationProviderRepository Repository { get; }
1010

11-
public ValidationConfiguration(IServiceCollection services, IValidationProviderRepository repository)
11+
public ValidationConfiguration(
12+
IServiceCollection services,
13+
IValidationProviderRepository repository)
1214
{
1315
Services = services ?? throw new ArgumentNullException(nameof(services));
1416
Repository = repository ?? throw new ArgumentNullException(nameof(repository));

src/PeterLeslieMorris.Blazor.Validation/ValidationProviderRepository.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public IValidationProviderRepository Add(Type providerType)
1414
if (providerType == null)
1515
throw new ArgumentNullException(nameof(providerType));
1616
if (!typeof(IValidationProvider).IsAssignableFrom(providerType))
17-
throw new ArgumentException($"{providerType.Name} does not implement {nameof(IValidationProvider)}");
17+
throw new ArgumentException($"{providerType.Name} " +
18+
$"does not implement {nameof(IValidationProvider)}");
1819

1920
Providers = Providers.Concat(new Type[] { providerType }).ToArray();
2021
return this;

src/PeterLeslieMorris.Blazor.Validation/ValidationServiceCollectionExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ namespace PeterLeslieMorris.Blazor.Validation
55
{
66
public static class ValidationServiceCollectionExtensions
77
{
8-
public static IServiceCollection AddFormValidation(this IServiceCollection instance, Action<ValidationConfiguration> config = null)
8+
public static IServiceCollection AddFormValidation(
9+
this IServiceCollection instance,
10+
Action<ValidationConfiguration> config = null)
911
{
1012
var repository = new ValidationProviderRepository();
1113
instance.AddScoped<IValidationProviderRepository>((_) => repository);

0 commit comments

Comments
 (0)