-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
026feee
commit d0a0630
Showing
7 changed files
with
127 additions
and
5 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
Examples/Validation/Examples.Validation.FluentValidation/ConfigurationContainer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Microsoft.Extensions.Configuration; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Examples.Validation.FluentValidation | ||
{ | ||
internal static class ConfigurationContainer | ||
{ | ||
public static IConfiguration Configuration { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
Examples/Validation/Examples.Validation.FluentValidation/ITestApplicationService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using RCommon.ApplicationServices.ExecutionResults; | ||
using RCommon.ApplicationServices.Validation; | ||
|
||
namespace Examples.Validation.FluentValidation | ||
{ | ||
public interface ITestApplicationService | ||
{ | ||
Task<ValidationOutcome> ExecuteTestMethod(TestDto dto); | ||
} | ||
} |
53 changes: 51 additions & 2 deletions
53
Examples/Validation/Examples.Validation.FluentValidation/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,51 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
Console.WriteLine("Hello, World!"); | ||
using Examples.Validation.FluentValidation; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using RCommon; | ||
using RCommon.ApplicationServices; | ||
using RCommon.ApplicationServices.ExecutionResults; | ||
using RCommon.FluentValidation; | ||
using System.Diagnostics; | ||
|
||
try | ||
{ | ||
var host = Host.CreateDefaultBuilder(args) | ||
.ConfigureAppConfiguration((context, builder) => | ||
{ | ||
ConfigurationContainer.Configuration = builder | ||
.Build(); | ||
}) | ||
.ConfigureServices(services => | ||
{ | ||
// Configure RCommon | ||
services.AddRCommon() | ||
.WithValidation<FluentValidationBuilder>(validation => | ||
{ | ||
validation.AddValidatorsFromAssemblyContaining(typeof(TestDto)); | ||
}); | ||
Console.WriteLine(services.GenerateServiceDescriptorsString()); | ||
services.AddTransient<ITestApplicationService, TestApplicationService>(); | ||
}).Build(); | ||
|
||
Console.WriteLine("Example Starting"); | ||
var appService = host.Services.GetRequiredService<ITestApplicationService>(); | ||
var validationOutcome1 = await appService.ExecuteTestMethod(new TestDto("")); // Will fail | ||
var validationOutcome2 = await appService.ExecuteTestMethod(new TestDto("test")); // Will pass | ||
|
||
Console.WriteLine(validationOutcome1.ToString()); | ||
Console.WriteLine("Validation Outcome 1 complete..."); | ||
Console.WriteLine(validationOutcome2.ToString()); | ||
Console.WriteLine("Validation Outcome 2 complete..."); | ||
|
||
Console.WriteLine("Example Complete"); | ||
Console.ReadLine(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(ex.ToString()); | ||
|
||
} | ||
|
27 changes: 27 additions & 0 deletions
27
Examples/Validation/Examples.Validation.FluentValidation/TestApplicationService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using RCommon.ApplicationServices.Commands; | ||
using RCommon.ApplicationServices.ExecutionResults; | ||
using RCommon.ApplicationServices.Queries; | ||
using RCommon.ApplicationServices.Validation; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Examples.Validation.FluentValidation | ||
{ | ||
public class TestApplicationService : ITestApplicationService | ||
{ | ||
private readonly IValidationService _validationService; | ||
|
||
public TestApplicationService(IValidationService validationService) | ||
{ | ||
_validationService = validationService; | ||
} | ||
|
||
public async Task<ValidationOutcome> ExecuteTestMethod(TestDto dto) | ||
{ | ||
return await _validationService.ValidateAsync(dto); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Examples/Validation/Examples.Validation.FluentValidation/TestDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Examples.Validation.FluentValidation | ||
{ | ||
public record TestDto | ||
{ | ||
public TestDto(string message) | ||
{ | ||
Message = message; | ||
} | ||
|
||
public string Message { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters