Skip to content

Commit 14ab3e5

Browse files
committed
Rename project
1 parent e47823e commit 14ab3e5

11 files changed

+213
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
publish.bat
2+
**/PublishProfiles/**
3+
secrets.txt
4+
15
## Ignore Visual Studio temporary files, build results, and
26
## files generated by popular Visual Studio add-ons.
37
##

LICENSE LICENCE

File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29006.145
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PeterLeslieMorris.Blazor.Validation", "PeterLeslieMorris.Blazor.Validation\PeterLeslieMorris.Blazor.Validation.csproj", "{07CE8E70-DF46-4A93-864B-1BBB64E52426}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{07CE8E70-DF46-4A93-864B-1BBB64E52426}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{07CE8E70-DF46-4A93-864B-1BBB64E52426}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{07CE8E70-DF46-4A93-864B-1BBB64E52426}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{07CE8E70-DF46-4A93-864B-1BBB64E52426}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {D95C3764-54F3-40FD-8A52-CB4D1F984806}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Microsoft.AspNetCore.Components.Forms;
2+
using Microsoft.Extensions.DependencyInjection;
3+
4+
namespace PeterLeslieMorris.Blazor.Validation
5+
{
6+
public class DataAnnotationsValidatorProvider : IValidationProvider
7+
{
8+
public void InitializeEditContext(EditContext editContext)
9+
{
10+
editContext.AddDataAnnotationsValidation();
11+
}
12+
}
13+
14+
public static class ValidationConfigurationDataAnnotationsExtensions
15+
{
16+
public static ValidationConfiguration AddDataAnnotationsValidation(this ValidationConfiguration config)
17+
{
18+
config.Services.AddScoped<DataAnnotationsValidatorProvider>();
19+
config.Repository.Add(typeof(DataAnnotationsValidatorProvider));
20+
return config;
21+
}
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace PeterLeslieMorris.Blazor.Validation
5+
{
6+
public interface IValidationProviderRepository
7+
{
8+
IEnumerable<Type> All { get; }
9+
IValidationProviderRepository Add(Type providerType);
10+
IValidationProviderRepository Remove(Type providerType);
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Microsoft.AspNetCore.Components.Forms;
2+
3+
namespace PeterLeslieMorris.Blazor.Validation
4+
{
5+
public interface IValidationProvider
6+
{
7+
void InitializeEditContext(EditContext editContext);
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Razor">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<IsPackable>true</IsPackable>
6+
<LangVersion>7.3</LangVersion>
7+
<RazorLangVersion>3.0</RazorLangVersion>
8+
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
9+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
10+
<PackageId>PeterLeslieMorris.Blazor.Validation</PackageId>
11+
<Version>0.1.0.0-pre</Version>
12+
<Authors>Peter Morris</Authors>
13+
<Company>Peter Morris</Company>
14+
<Product>PeterLeslieMorris.Blazor.Validation</Product>
15+
<Description>Validation for Blazor</Description>
16+
<Copyright>Peter Morris</Copyright>
17+
<PackageLicenseFile>LICENCE</PackageLicenseFile>
18+
<PackageProjectUrl>https://github.com/mrpmorris/blazor-validation</PackageProjectUrl>
19+
<PackageIconUrl>https://raw.githubusercontent.com/mrpmorris/blazor-validation/master/docs/images/blazor-validation-logo-small.png</PackageIconUrl>
20+
<RepositoryUrl>https://github.com/mrpmorris/blazor-validation</RepositoryUrl>
21+
<PackageTags>blazor validation fluent</PackageTags>
22+
</PropertyGroup>
23+
24+
<ItemGroup>
25+
<!-- .js/.css files will be referenced via <script>/<link> tags; other content files will just be included in the app's 'dist' directory without any tags referencing them -->
26+
<EmbeddedResource Include="content\**\*.js" LogicalName="blazor:js:%(RecursiveDir)%(Filename)%(Extension)" />
27+
<EmbeddedResource Include="content\**\*.css" LogicalName="blazor:css:%(RecursiveDir)%(Filename)%(Extension)" />
28+
<EmbeddedResource Include="content\**" Exclude="**\*.js;**\*.css" LogicalName="blazor:file:%(RecursiveDir)%(Filename)%(Extension)" />
29+
</ItemGroup>
30+
31+
<ItemGroup>
32+
<PackageReference Include="Microsoft.AspNetCore.Components.Browser" Version="3.0.0-preview6.19307.2" />
33+
</ItemGroup>
34+
35+
<ItemGroup>
36+
<None Include="..\..\LICENCE">
37+
<Pack>True</Pack>
38+
<PackagePath></PackagePath>
39+
</None>
40+
</ItemGroup>
41+
42+
<ItemGroup>
43+
<Folder Include="content\" />
44+
</ItemGroup>
45+
46+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Microsoft.AspNetCore.Components;
2+
using Microsoft.AspNetCore.Components.Forms;
3+
using System;
4+
5+
namespace PeterLeslieMorris.Blazor.Validation
6+
{
7+
public class Validate : ComponentBase
8+
{
9+
[CascadingParameter] EditContext CurrentEditContext { get; set; }
10+
[Inject] IValidationProviderRepository Repository { get; set; }
11+
[Inject] IServiceProvider ServiceProvider { get; set; }
12+
13+
protected override void OnInit()
14+
{
15+
if (CurrentEditContext == null)
16+
{
17+
throw new InvalidOperationException($"{nameof(DataAnnotationsValidator)} requires a cascading " +
18+
$"parameter of type {nameof(EditContext)}. For example, you can use {nameof(DataAnnotationsValidator)} " +
19+
$"inside an {nameof(EditForm)}.");
20+
}
21+
foreach (Type providerType in Repository.All)
22+
{
23+
IValidationProvider validationProvider = (IValidationProvider)ServiceProvider.GetService(providerType);
24+
validationProvider.InitializeEditContext(CurrentEditContext);
25+
}
26+
}
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
using System;
3+
4+
namespace PeterLeslieMorris.Blazor.Validation
5+
{
6+
public class ValidationConfiguration
7+
{
8+
public IServiceCollection Services { get; }
9+
public IValidationProviderRepository Repository { get; }
10+
11+
public ValidationConfiguration(IServiceCollection services, IValidationProviderRepository repository)
12+
{
13+
Services = services ?? throw new ArgumentNullException(nameof(services));
14+
Repository = repository ?? throw new ArgumentNullException(nameof(repository));
15+
}
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace PeterLeslieMorris.Blazor.Validation
6+
{
7+
public class ValidationProviderRepository : IValidationProviderRepository
8+
{
9+
private Type[] Providers = new Type[0];
10+
public IEnumerable<Type> All => Providers;
11+
12+
public IValidationProviderRepository Add(Type providerType)
13+
{
14+
if (providerType == null)
15+
throw new ArgumentNullException(nameof(providerType));
16+
if (!typeof(IValidationProvider).IsAssignableFrom(providerType))
17+
throw new ArgumentException($"{providerType.Name} does not implement {nameof(IValidationProvider)}");
18+
19+
Providers = Providers.Concat(new Type[] { providerType }).ToArray();
20+
return this;
21+
}
22+
23+
public IValidationProviderRepository Remove(Type providerType)
24+
{
25+
Providers = Providers.Where(x => x != providerType).ToArray();
26+
return this;
27+
}
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
using System;
3+
4+
namespace PeterLeslieMorris.Blazor.Validation
5+
{
6+
public static class ValidationServiceCollectionExtensions
7+
{
8+
public static IServiceCollection AddFormValidation(this IServiceCollection instance, Action<ValidationConfiguration> config = null)
9+
{
10+
var repository = new ValidationProviderRepository();
11+
instance.AddScoped<IValidationProviderRepository>((_) => repository);
12+
if (config != null)
13+
{
14+
var c = new ValidationConfiguration(instance, repository);
15+
config(c);
16+
}
17+
return instance;
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)