Skip to content

Commit

Permalink
return OptionsBuilder on AddAsyncValidation; Add test console project
Browse files Browse the repository at this point in the history
  • Loading branch information
R0boC0p committed May 24, 2024
1 parent d46bcb6 commit cfde03e
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 2 deletions.
6 changes: 6 additions & 0 deletions AsyncValidation.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AsyncValidation.Test", "src\AsyncValidation.Test\AsyncValidation.Test.csproj", "{91B39B06-A337-4946-9BE9-259312BBE863}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestService", "src\AsyncValidatoin.TestService\TestService\TestService.csproj", "{A885D376-2042-4DFC-A77B-CA631535A2C2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -27,6 +29,10 @@ Global
{91B39B06-A337-4946-9BE9-259312BBE863}.Debug|Any CPU.Build.0 = Debug|Any CPU
{91B39B06-A337-4946-9BE9-259312BBE863}.Release|Any CPU.ActiveCfg = Release|Any CPU
{91B39B06-A337-4946-9BE9-259312BBE863}.Release|Any CPU.Build.0 = Release|Any CPU
{A885D376-2042-4DFC-A77B-CA631535A2C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A885D376-2042-4DFC-A77B-CA631535A2C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A885D376-2042-4DFC-A77B-CA631535A2C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A885D376-2042-4DFC-A77B-CA631535A2C2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 2 additions & 2 deletions src/AsyncValidation/Extensions/ValidationExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Mvc.AsyncValidation.Extensions;

public static class ValidationExtension
{
public static IServiceCollection AddAsyncValidation(this IServiceCollection services)
public static OptionsBuilder<MvcOptions> AddAsyncValidation(this IServiceCollection services)
{
services.AddSingleton<IConfigureOptions<MvcOptions>, ConfigureMVCOptionsSetup>();
services.AddSingleton<ParameterBinder, AsyncParamterBinder>();
Expand All @@ -23,7 +23,7 @@ public static IServiceCollection AddAsyncValidation(this IServiceCollection serv
var metadataProvider = s.GetRequiredService<IModelMetadataProvider>();
return new AsyncObjectModelValidator(metadataProvider, options.ModelValidatorProviders, cache, options);
});
return services;
return services.AddOptions<MvcOptions>();
}

internal sealed class ConfigureMVCOptionsSetup : IConfigureOptions<MvcOptions>
Expand Down
60 changes: 60 additions & 0 deletions src/AsyncValidatoin.TestService/TestService/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.AsyncValidation.Extensions;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace Microsoft.AspNetCore.Mvc.AsyncValidation;

class Program
{
static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args)
{
return Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(configure =>
{
configure.UseStartup<Startup>();
})
.ConfigureServices(services =>
{
services.AddMvc(opt => opt.EnableEndpointRouting = false);
services.AddAsyncValidation()
.Configure(opt =>
{
opt.MaxValidationDepth = null;
});
});
}
}

public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// Add services to the container.
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseRouting();

app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
20 changes: 20 additions & 0 deletions src/AsyncValidatoin.TestService/TestService/TestService.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\AsyncValidation\AsyncValidation.csproj" />
</ItemGroup>

</Project>

0 comments on commit cfde03e

Please sign in to comment.