diff --git a/samples/StateMachine/Trax.Samples.StateMachine.Api/Program.cs b/samples/StateMachine/Trax.Samples.StateMachine.Api/Program.cs index dc52005..7b4c325 100644 --- a/samples/StateMachine/Trax.Samples.StateMachine.Api/Program.cs +++ b/samples/StateMachine/Trax.Samples.StateMachine.Api/Program.cs @@ -2,7 +2,7 @@ // Trax State Machine sample — a GraphQL host over two fluent machines. // // Two machines, authored fluently in Trax.Samples.StateMachine, are discovered with one line -// (AddTraxStateMachines) and driven through the four generic `stateMachine` mutations: +// (AddStateMachines) and driven through the four generic `stateMachine` mutations: // turnstile Locked ⇄ Unlocked (no effect) // checkout Cart → Review → Paid (Paid committed, one exactly-once charge on Pay) // @@ -32,7 +32,6 @@ // }) { output { snapshot problem { code } } } } } } // ───────────────────────────────────────────────────────────────────────────── -using Microsoft.EntityFrameworkCore; using Trax.Api.Auth.ApiKey; using Trax.Api.Extensions; using Trax.Api.GraphQL.Extensions; @@ -40,7 +39,6 @@ using Trax.Effect.Extensions; using Trax.Effect.Provider.Json.Extensions; using Trax.Effect.StateMachine.Persistence; -using Trax.Effect.StateMachine.Persistence.Mutations; using Trax.Mediator.Extensions; using Trax.Samples.StateMachine; using Trax.Samples.StateMachine.Api; @@ -59,24 +57,21 @@ ); builder.Services.AddAuthorization(); -// Trax + the state machine. The mediator scan includes StateMachineMutations.Assembly so the four generic -// mutations route by input type; AddTraxStateMachines discovers the machines in the sample library and -// wires the store, the effect-claim ledger, the exactly-once runner, and the registry. +// Trax + the state machine, in one builder chain. AddStateMachines discovers the machines in the sample +// library, wires the store / effect-claim ledger / exactly-once runner / registry, AUTO-registers the +// SnapshotDbContext against the Postgres provider above, and contributes the four generic `stateMachine` +// mutations to the mediator scan. The host names neither SnapshotDbContext nor the mutations' assembly. +// (Call AddStateMachines before AddMediator: the mediator builds its route registry when it runs.) builder.Services.AddTrax(trax => trax.AddEffects(effects => effects.UsePostgres(connectionString).AddJson()) - .AddMediator(typeof(TurnstileMachine).Assembly, StateMachineMutations.Assembly) + .AddStateMachines(typeof(TurnstileMachine).Assembly) + .AddMediator(typeof(TurnstileMachine).Assembly) ); -builder.Services.AddTraxStateMachines(typeof(TurnstileMachine).Assembly); // The two host-supplied bindings a machine can't know: map auth to a user key, and the charge impl. builder.Services.AddScoped(); builder.Services.AddScoped(); -// The snapshot store's DbContext. The snapshot_draft + effect_claim tables are created by the -// Trax migration set: UsePostgres above runs DbUp, which applies 040_state_machine_snapshots.sql. -// Nothing here creates tables — `docker compose up -d` (a `trax` database) is all that's needed. -builder.Services.AddDbContext(options => options.UseNpgsql(connectionString)); - builder.Services.AddTraxGraphQL(graphql => graphql); builder.Services.AddHealthChecks().AddTraxHealthCheck(); diff --git a/samples/StateMachine/Trax.Samples.StateMachine/Machines.cs b/samples/StateMachine/Trax.Samples.StateMachine/Machines.cs index e62a9a0..8d34979 100644 --- a/samples/StateMachine/Trax.Samples.StateMachine/Machines.cs +++ b/samples/StateMachine/Trax.Samples.StateMachine/Machines.cs @@ -7,7 +7,7 @@ namespace Trax.Samples.StateMachine; // Two worked-example machines, authored with the fluent API. A host discovers them with one line -// (AddTraxStateMachines) and drives them through the four generic `stateMachine` GraphQL mutations. The +// (AddStateMachines) and drives them through the four generic `stateMachine` GraphQL mutations. The // turnstile is the pure-structure proof (no effect); the checkout is the effectful proof (a committed state // and one irreversible charge, fired exactly once).