Advertisement
manura8235

Untitled

Aug 5th, 2024
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. Program.cs
  2.  
  3. using FastEndpoints;
  4. using FastEndpoints.Swagger;
  5.  
  6. var builder = WebApplication.CreateBuilder(args);
  7.  
  8. // Add services to the container.
  9.  
  10. builder.Services.AddAuthorization();
  11. builder.Services.AddFastEndpoints()
  12. .SwaggerDocument(o =>
  13. {
  14. o.MaxEndpointVersion = 1;
  15. o.DocumentSettings = s =>
  16. {
  17. s.DocumentName = "V1";
  18. s.Title = "API";
  19. s.Version = "v1.0";
  20. };
  21. }).AddLocalization(opt => opt.ResourcesPath = "Resources");
  22.  
  23.  
  24. var app = builder.Build();
  25.  
  26. // Configure the HTTP request pipeline.
  27. if (!app.Environment.IsProduction())
  28. {
  29. app.UseSwaggerGen();
  30. }
  31.  
  32. app.UseFastEndpoints(c =>
  33. {
  34. c.Versioning.Prefix = "v";
  35. c.Versioning.PrependToRoute = true;
  36. }).UseRequestLocalization(options =>
  37. options
  38. .AddSupportedCultures(new string[] { "en-US" })
  39. .AddSupportedUICultures(new string[] { "en-US" })
  40. .SetDefaultCulture("en-US")
  41. );
  42.  
  43.  
  44. app.UseAuthorization();
  45.  
  46.  
  47. app.Run();
  48.  
  49. namespace FastendpointsTest;
  50.  
  51. public class WeatherForecastRequest
  52. {
  53. public int? CountryId { get; set; }
  54.  
  55. public required DemographicData DemographicData { get; set; }
  56. }
  57.  
  58. public class DemographicData
  59. {
  60. public int? CountrySecret { get; set; }
  61.  
  62. public string? CountryCode { get; set; }
  63. }
  64.  
  65.  
  66. using FastEndpoints;
  67. using FluentValidation;
  68. using Microsoft.Extensions.Localization;
  69.  
  70. namespace FastendpointsTest;
  71.  
  72. public class Validator : Validator<WeatherForecastRequest>
  73. {
  74.  
  75.  
  76. public Validator(IStringLocalizer<SampleMessages> localizer)
  77. {
  78. RuleFor(x => x.CountryId).NotEmpty().WithMessage(localizer["Countryid"].Value);
  79. RuleFor(p => p.DemographicData).SetValidator(new DemographicDataValidator(localizer));
  80. }
  81. }
  82.  
  83.  
  84. public class DemographicDataValidator : Validator<DemographicData>
  85. {
  86. public DemographicDataValidator()
  87. {
  88.  
  89. }
  90.  
  91. public DemographicDataValidator(IStringLocalizer<SampleMessages> localizer)
  92. {
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement