25 releases
| new 0.2.41 | Nov 28, 2025 |
|---|---|
| 0.2.40 | Nov 27, 2025 |
| 0.2.39 | Oct 27, 2025 |
| 0.2.23 | Sep 30, 2025 |
| 0.1.0 | Sep 26, 2025 |
#1367 in Development tools
595 downloads per month
Used in 4 crates
(3 directly)
92KB
2K
SLoC
cardinal-base
cardinal-base underpins the gateway’s dependency graph. It hosts the DI container, routing utilities, and destination resolver used everywhere else.
Components
CardinalContext– owns the activeCardinalConfig, tracks provider registrations, and constructs providers on demand. Scope-aware (SingletonvsTransient) with cycle detection to keep async factories honest.- Provider traits – implement
Providerfor any type you want to resolve later. Register withregister,register_with_factory, orregister_singleton_instance. CardinalRouter– small wrapper aroundmatchit::Router; used by destinations to match HTTP method + path and extract path parameters.DestinationContainer– buildsDestinationWrappers from config, supplies per-destination middleware lists, and picks a backend by path segment or subdomain.
How it fits
At runtime the flow looks like this:
CardinalBuilder
└─ registers providers in CardinalContext
├─ DestinationContainer (maps host/path → backend + middleware)
├─ PluginContainer (middleware registry)
└─ any user-provided services
When cardinal-proxy handles a request it grabs the DestinationContainer and (if routes were declared) queries the CardinalRouter to validate the path and extract parameters. Middleware lists are pulled from each DestinationWrapper and fed to the plugin runner.
Adding new providers
struct Metrics;
#[async_trait::async_trait]
impl Provider for Metrics {
async fn provide(ctx: &CardinalContext) -> Result<Self, CardinalError> {
// optional: use ctx.config to decide setup
Ok(Metrics)
}
}
context.register::<Metrics>(ProviderScope::Singleton);
Later, middleware or infrastructure code can ask for context.get::<Metrics>().await? and work with the shared instance.
Dependencies
~34–51MB
~1M SLoC