-
-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Required] doesn't seem to have an effect #505
Comments
Some extra context :) Program.cs
using System.Net.Http.Headers;
using Authentication;
using Happydogs.Domain;
using Happydogs.ReadModels;
using Marten;
using Oakton;
using Oakton.Resources;
using Wolverine;
using Wolverine.Http;
using Wolverine.Marten;
using Wolverine.Postgresql;
using OpenTelemetry.Trace;
using Marten.Events.Daemon.Resiliency;
using Marten.Events.Projections;
using Marten.Services.Json;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Net.Http.Headers;
using Npgsql;
using OpenTelemetry.Resources;
using Svix;
using Utility.Api;
using Web.Configure;
using Wolverine.FluentValidation;
using Wolverine.Http.FluentValidation;
var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddJsonFile("appsettings.local.json", optional: true).AddEnvironmentVariables();
string clerkApiKey = builder.Configuration["Clerk:ApiKey"] ?? throw new Exception("No Clerk API key found");
string clerkAuthority = builder.Configuration["Clerk:ClerkAPI"] ?? throw new Exception("No Clerk API found");
string sendgridApiKey = builder.Configuration["SendGrid:ApiKey"] ?? throw new Exception("No SendGrid API key found");
string connectionString = builder.Configuration["ConnectionStrings:postgres"] ?? throw new Exception("No connection string found");
string clerkWebhookSecret = builder.Configuration["Clerk:WebhookSecret"] ?? throw new Exception("No Clerk webhook secret found");
string notionApiKey = builder.Configuration["Notion:ApiKey"] ?? throw new Exception("No Notion API Key found");
builder.Host.ApplyOaktonExtensions();
builder.Host.UseResourceSetupOnStartup();
// builder.Host.UseSerilog();
builder.Services.AddSingleton<Webhook>(_ => new Webhook(clerkWebhookSecret));
builder.Services.AddNotionClient(options => { options.AuthToken = notionApiKey; });
builder.Services.AddHttpClient("SendGrid", (provider, client) =>
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", sendgridApiKey);
client.BaseAddress = new Uri("https://api.sendgrid.com");
});
builder.Services.AddHttpClient<ClerkClient>((provider, client) =>
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", clerkApiKey);
client.BaseAddress = new Uri("https://api.clerk.com");
});
builder.Services.AddCors(options =>
{
options.AddPolicy(name: "_happydogsServers",
policy =>
{
policy.WithOrigins("https://happydogs.no", "http://localhost:3000")
.WithHeaders(HeaderNames.Authorization, HeaderNames.ContentType, HeaderNames.Accept);
});
});
builder.Services.AddClerkAuthentication(clerkAuthority);
builder.Services.AddSvixAuthentication(clerkWebhookSecret);
builder.Services.Configure<CloudflareOptions>(o =>
{
o.AccessKey = builder.Configuration["Cloudflare:AccessKey"] ?? throw new Exception("No Cloudflare access key found");
o.SecretKey = builder.Configuration["Cloudflare:SecretKey"] ?? throw new Exception("No Cloudflare secret key found");
o.AccountId = builder.Configuration["Cloudflare:AccountId"] ?? throw new Exception("No Cloudflare account ID found");
o.Bucket = builder.Configuration["Cloudflare:Bucket"] ?? throw new Exception("No Cloudflare bucket found");
});
builder.Services.AddScoped<Cloudflare>();
var happydogsAssembly = typeof(Happydogs.Domain.AggregateBase).Assembly;
builder.Services.AddControllers()
.AddApplicationPart(happydogsAssembly)
.AddControllersAsServices();
// Add services to the container
builder.Services.AddMarten(opts =>
{
opts.Connection(connectionString);
opts.UseDefaultSerialization(serializerType: SerializerType.SystemTextJson );
opts.Events.MetadataConfig.HeadersEnabled = true;
opts.Events.MetadataConfig.CausationIdEnabled = true;
opts.Events.MetadataConfig.CorrelationIdEnabled = true;
opts.Events.AddEventTypes(
typeof(EventBase)
.Assembly
.GetTypes()
.Where(typeof(EventBase).IsAssignableFrom));
opts.Projections.Add<MembersProjection>(ProjectionLifecycle.Async);
opts.Projections.Add<MemberBreederProjection>(ProjectionLifecycle.Async);
opts.Projections.Add<DogMemberProjection>(ProjectionLifecycle.Async);
opts.Projections.Add<DogsProjection>(ProjectionLifecycle.Async);
opts.Projections.Add<BreedersProjection>(ProjectionLifecycle.Async);
})
.IntegrateWithWolverine()
.UseLightweightSessions()
.AddAsyncDaemon(DaemonMode.Solo)
.ApplyAllDatabaseChangesOnStartup()
.InitializeWith();
builder.Host.UseWolverine(opts =>
{
opts.PersistMessagesWithPostgresql(connectionString);
// This middleware will apply to the HTTP
// endpoints as well
opts.Policies.AutoApplyTransactions();
// Setting up the outbox on all locally handled
// background tasks
opts.Policies.UseDurableLocalQueues();
opts.Discovery.IncludeAssembly(happydogsAssembly);
opts.UseFluentValidation();
});
builder.Services.AddOpenTelemetry()
.ConfigureResource(b => b.AddService(serviceName: "HappyDogs"))
.WithTracing(b => b
.AddAspNetCoreInstrumentation()
.AddOtlpExporter()
.AddNpgsql()
.AddSource("Wolverine")
);
builder.Services.AddSingleton<AggregateRepository>();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddHappyDogsSwagger();
var app = builder.Build();
app.UseCors("_happydogsServers");
// app.UseSvixAuthMiddleware();
app.UseAuthentication();
app.UseAuthorization();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.MapGet("/hello", [Authorize](HttpContext context) => "Hello World!");
// Let's add in Wolverine HTTP endpoints to the routing tree
app.MapWolverineEndpoints(opts =>
{
opts.UseFluentValidationProblemDetailMiddleware();
});
return await app.RunOaktonCommands(args); My public async Task<T?> LoadAsync<T>(
Guid id,
int? version = null,
CancellationToken ct = default
) where T : AggregateBase
{
await using var session = await _store.LightweightSerializableSessionAsync(token: ct);
var aggregate = await session.Events.AggregateStreamAsync<T>(id, version ?? 0, token: ct);
if (aggregate is null || aggregate.Version == 0)
{
return null;
}
return aggregate;
} |
@Richard87 It didn't catch on that because Wolverine had been coded to only care about [Required] if the route had any parameters. I guess I don't care enough about whether that was true or not, so I widened the applicability to "any method argument w/ [Required]" to fix this. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have this code
That produces this output:
The text was updated successfully, but these errors were encountered: