-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
76 lines (67 loc) · 3.25 KB
/
Program.cs
File metadata and controls
76 lines (67 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
using SampleMinimalApiNoAot.API;
using SampleUserLibrary;
using Trellis;
using Trellis.Asp;
var builder = WebApplication.CreateBuilder(args);
// NO JsonSerializerContext - uses standard JSON serialization with reflection fallback
// This demonstrates that the library works perfectly without source generation!
builder.Services.AddScalarValueValidationForMinimalApi();
Action<ResourceBuilder> configureResource = r => r.AddService(
serviceName: "SampleMinimalApiNoAot",
serviceVersion: typeof(Program).Assembly.GetName().Version?.ToString() ?? "unknown");
builder.Services.AddOpenTelemetry()
.ConfigureResource(configureResource)
.WithTracing(tracing
=> tracing.AddSource("SampleMinimalApiNoAot")
.SetSampler(new AlwaysOnSampler())
.AddPrimitiveValueObjectInstrumentation()
.AddOtlpExporter());
var app = builder.Build();
app.UseScalarValueValidation();
// Welcome endpoint with API information
#pragma warning disable CA1861 // Prefer 'static readonly' fields - one-time startup configuration
app.MapGet("/", () => Results.Ok(new
{
name = "FunctionalDDD Sample Minimal API (No AOT)",
version = "1.0.0",
description = "Demonstrates FunctionalDDD Railway Oriented Programming with Minimal APIs and reflection fallback (no source generation)",
endpoints = new
{
users = new
{
register = "POST /users/register - Register user with manual validation (Result.Combine)",
registerCreated = "POST /users/registerCreated - Register user returning 201 Created",
registerAutoValidation = "POST /users/RegisterWithAutoValidation - Register with auto-validation (Maybe<Url> for optional website)",
errors = new string[]
{
"GET /users/notfound/{id} - Returns 404 Not Found",
"GET /users/conflict/{id} - Returns 409 Conflict",
"GET /users/forbidden/{id} - Returns 403 Forbidden",
"GET /users/unauthorized/{id} - Returns 401 Unauthorized",
"GET /users/unexpected/{id} - Returns 500 Internal Server Error"
}
},
orders = new
{
getStates = "GET /orders/states - Get all order states (RequiredEnum demo)",
getStateByName = "GET /orders/states/{state} - Get state by name (model binding)",
updateOrder = "POST /orders/update - Update order with RequiredEnum and optional Maybe assignedTo",
createOrder = "POST /orders/create - Create order with multiple value objects",
filterOrders = "GET /orders/filter?state=Draft - Filter orders by state (query string)"
}
},
documentation = "See SampleApi.http for complete API examples"
})).WithName("Welcome");
#pragma warning restore CA1861
app.UseUserRoute();
app.UseMoneyRoute();
app.UseOrderRoute();
app.Run();
#pragma warning disable CA1050 // Declare types in namespaces
public record SharedNameTypeResponse(string FirstName, string LastName, string Email, string Message);
#pragma warning restore CA1050 // Declare types in namespaces
// NO [GenerateScalarValueConverters] attribute
// NO JsonSerializerContext
// Uses standard reflection-based JSON serialization - works perfectly!