added two samples

This commit is contained in:
2026-02-03 08:31:53 -05:00
parent 97e0ce1733
commit 51f577d218
1120 changed files with 45859 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Messages\Messages.csproj" />
<ProjectReference Include="..\ServiceDefaults\ServiceDefaults.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Aspire.Npgsql" Version="13.1.0" />
<PackageReference Include="WolverineFx.Marten" Version="5.13.0" />
<PackageReference Include="WolverineFx.Nats" Version="5.13.0" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,44 @@
using Messages;
using Wolverine;
namespace ApiOne.Endpoints;
public static class Extensions
{
extension(IEndpointRouteBuilder endpoints)
{
public IEndpointRouteBuilder MapApiOneEndpoints()
{
endpoints.MapPost("/messages", async (SendMessage request, IMessageBus messageBus) =>
{
await messageBus.PublishAsync(request);
return Results.Accepted();
});
endpoints.MapPost("/math", async (AddThem request, IMessageBus bus) =>
{
var result = await bus.InvokeAsync<NumbersAdded>(request);
return Results.Ok(result);
});
endpoints.MapPost("/users", async (UserCreate user, IMessageBus bus) =>
{
var doc = new UserDocument(Guid.NewGuid(), user.Name);
await bus.PublishAsync(doc);
return Results.Accepted();
});
endpoints.MapPut("/users/{id:guid}/name", async (Guid id, UserCreate user, IMessageBus bus) =>
{
var nameChanged = new UserNameChanged(id, user.Name);
await bus.PublishAsync(nameChanged);
return Results.Accepted();
});
return endpoints;
}
}
}
public record UserCreate(string Name);

View File

@@ -0,0 +1,56 @@
using ApiOne.Endpoints;
using Marten;
using Messages;
using Wolverine;
using Wolverine.Marten;
using Wolverine.Nats;
var builder = WebApplication.CreateBuilder(args);
builder.AddServiceDefaults();
builder.AddNpgsqlDataSource("db-one");
builder.UseWolverine(options =>
{
options.UseNats(builder.Configuration.GetConnectionString("nats") ??
throw new Exception("No NATS connection string configured"))
.AutoProvision()
.UseJetStream(js =>
{
js.MaxDeliver = 5;
js.AckWait = TimeSpan.FromSeconds(30);
})
.DefineStream("PEOPLE", stream =>
stream.WithSubject("people.>")
.WithLimits(maxMessages: 5_000, maxAge: TimeSpan.FromDays(5))
//.WithReplicas(3)
.EnableScheduledDelivery());
options.PublishMessage<SendMessage>()
.ToNatsSubject("messages-sent");
options.PublishMessage<UserDocument>()
.ToNatsSubject("people.created");
options.PublishMessage<UserNameChanged>()
.ToNatsSubject("people.name-changed");
options.PublishMessage<AddThem>()
.ToNatsSubject("math.add");
});
builder.Services.AddMarten(config =>
{
}).UseLightweightSessions()
.IntegrateWithWolverine()
.UseNpgsqlDataSource();
var app = builder.Build();
app.MapGet("/", () => "Hello World!");
app.MapApiOneEndpoints();
app.MapDefaultEndpoints();
app.Run();

View File

@@ -0,0 +1,15 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "https://apione.dev.localhost:7131",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@@ -0,0 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Npgsql": "Warning"
}
},
"AllowedHosts": "*"
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,19 @@
{
"runtimeOptions": {
"tfm": "net10.0",
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "10.0.0"
},
{
"name": "Microsoft.AspNetCore.App",
"version": "10.0.0"
}
],
"configProperties": {
"System.GC.Server": true,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
}
}
}

View File

@@ -0,0 +1 @@
{"Version":1,"ManifestType":"Build","Endpoints":[]}

View File

@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@@ -0,0 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Npgsql": "Warning"
}
},
"AllowedHosts": "*"
}

Some files were not shown because too many files have changed in this diff Show More