Skip to content

Repository files navigation

Trax.Mediator

Build NuGet codecov License: MIT Docs

Part of Trax: business logic you can call, schedule, or serve as an API, with every run recorded in your Postgres. Docs · Getting started · All repos

Trax.Mediator is the train bus for Trax: run a train by its input type, with every chain checked at host startup. It builds on Trax.Effect, and Trax.Scheduler and Trax.Api run their trains through it.

Install

dotnet add package Trax.Mediator
dotnet add package Trax.Effect.Data.Postgres    # or Trax.Effect.Data.Sqlite, Trax.Effect.Data.InMemory
dotnet add package Trax.Mediator.Testing        # optional, architecture guards for your test project

Trax.Effect and Trax.Core come in transitively. The storage package is where each run's record is written.

Example

Adapted from the game server sample. Register the assembly that holds your trains, then hand an input to ITrainBus:

builder.Services.AddTrax(trax => trax
    .AddEffects(effects => effects.UsePostgres(connectionString))
    .AddMediator(typeof(RecalculateLeaderboardTrain).Assembly));

public class LeaderboardController(ITrainBus trains) : ControllerBase
{
    [HttpPost("leaderboard/{region}/recalculate")]
    public Task<RecalculateLeaderboardOutput> Recalculate(string region) =>
        trains.RunAsync<RecalculateLeaderboardOutput>(
            new RecalculateLeaderboardInput { Region = region });
}

The controller never names the train: the bus runs the one registered for RecalculateLeaderboardInput and records the run. A chain that can never be satisfied stops the host at startup.

Where this fits

Trax is split into layers, one repo each. Take the ones you need; the trains you wrote do not change. You are here: Trax.Mediator.

Repo What it adds
Trax.Core Trains, junctions and the chain, with no database and no DI container
Trax.Effect A recorded run for every execution (Postgres, SQLite or in memory), DI, effect providers, the state-machine engine
Trax.Mediator The train bus: run a train by handing over its input, with every chain checked at startup
Trax.Scheduler Cron and interval schedules, retries, dead letters, and workers on other machines or in Lambda
Trax.Api GraphQL generated from your trains, with authentication, audit and typed clients
Trax.Dashboard A Blazor Server UI for runs, schedules and dead letters, mounted in your app
Trax.Cli The trax tool: scaffold a hub and trains from an OpenAPI or GraphQL schema, and state-machine codegen
Trax.Samples Complete sample apps, and the trax-api, trax-scheduler and trax-hub templates

Docs live in Trax.Docs and are published at traxsharp.net/docs.

Contributing

Read AGENTS.md before changing code. Report vulnerabilities privately as described in SECURITY.md.

License

MIT. There is no commercial edition, and there will not be one.

Trax is an independent open-source project and is not affiliated with the Utah Transit Authority, Trax Retail, or any other organization using the Trax name.

About

Resources

Security policy

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages