Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program.cs
- using FastEndpoints;
- using FastEndpoints.Swagger;
- var builder = WebApplication.CreateBuilder(args);
- // Add services to the container.
- builder.Services.AddAuthorization();
- builder.Services.AddFastEndpoints()
- .SwaggerDocument(o =>
- {
- o.MaxEndpointVersion = 1;
- o.DocumentSettings = s =>
- {
- s.DocumentName = "V1";
- s.Title = "API";
- s.Version = "v1.0";
- };
- }).AddLocalization(opt => opt.ResourcesPath = "Resources");
- var app = builder.Build();
- // Configure the HTTP request pipeline.
- if (!app.Environment.IsProduction())
- {
- app.UseSwaggerGen();
- }
- app.UseFastEndpoints(c =>
- {
- c.Versioning.Prefix = "v";
- c.Versioning.PrependToRoute = true;
- }).UseRequestLocalization(options =>
- options
- .AddSupportedCultures(new string[] { "en-US" })
- .AddSupportedUICultures(new string[] { "en-US" })
- .SetDefaultCulture("en-US")
- );
- app.UseAuthorization();
- app.Run();
- namespace FastendpointsTest;
- public class WeatherForecastRequest
- {
- public int? CountryId { get; set; }
- public required DemographicData DemographicData { get; set; }
- }
- public class DemographicData
- {
- public int? CountrySecret { get; set; }
- public string? CountryCode { get; set; }
- }
- using FastEndpoints;
- using FluentValidation;
- using Microsoft.Extensions.Localization;
- namespace FastendpointsTest;
- public class Validator : Validator<WeatherForecastRequest>
- {
- public Validator(IStringLocalizer<SampleMessages> localizer)
- {
- RuleFor(x => x.CountryId).NotEmpty().WithMessage(localizer["Countryid"].Value);
- RuleFor(p => p.DemographicData).SetValidator(new DemographicDataValidator(localizer));
- }
- }
- public class DemographicDataValidator : Validator<DemographicData>
- {
- public DemographicDataValidator()
- {
- }
- public DemographicDataValidator(IStringLocalizer<SampleMessages> localizer)
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement