pub trait IServiceCollectionExt: Sized {
// Required methods
fn add_mediator(self) -> Self;
fn add_request_endpoints(self) -> Self;
fn add_controllers(self) -> Self;
fn add_middleware<T>(self) -> Self
where T: IMiddleware + Default + Send + Sync + 'static;
fn add_typed_pipeline<B, Req, Rsp>(self) -> Self
where B: IPipelineBehavior<Req, Rsp> + Default + 'static,
Req: Send + 'static,
Rsp: Send + 'static;
fn add_typed_pipeline_with<F, Req, Rsp>(self, factory: F) -> Self
where F: Fn(&dyn IServiceResolver) -> Arc<dyn IPipelineBehavior<Req, Rsp>> + Send + Sync + 'static,
Req: Send + 'static,
Rsp: Send + 'static;
fn add_pipeline<T>(self) -> Self
where T: IErasedPipelineBehavior + Default + Send + Sync + 'static;
fn add_pipeline_with<F>(self, factory: F) -> Self
where F: Fn(&dyn IServiceResolver) -> Arc<dyn IErasedPipelineBehavior> + Send + Sync + 'static;
fn add_hosted_service<T>(self) -> Self
where T: IHostedService + Default + Send + Sync + 'static;
}Expand description
Extension methods for rust_dix::ServiceCollection to enable
framework-level service registration patterns.
Required Methods§
Sourcefn add_mediator(self) -> Self
fn add_mediator(self) -> Self
Register the mediator in the DI container.
The actual IRequestHandler and IEventHandler implementations
are registered via #[rust_dix::module] blocks (re-exported as webx::module).
Sourcefn add_request_endpoints(self) -> Self
fn add_request_endpoints(self) -> Self
Signal that endpoints should be auto-discovered from #[get] / #[endpoint]
annotations at compile time. The actual route table is built during
Host::build() by scanning the inventory for RouteEntry items.
Sourcefn add_controllers(self) -> Self
fn add_controllers(self) -> Self
Register controller types scoped per request.
Sourcefn add_middleware<T>(self) -> Self
fn add_middleware<T>(self) -> Self
Register a middleware type in the DI container as a singleton.
Sourcefn add_typed_pipeline<B, Req, Rsp>(self) -> Self
fn add_typed_pipeline<B, Req, Rsp>(self) -> Self
Register a typed pipeline behavior in the DI container as a singleton.
B declares the request/response types by implementing
IPipelineBehavior<Req, Rsp>; register those same types here:
#[derive(Default)]
struct AuditBehavior;
#[async_trait::async_trait]
impl IPipelineBehavior<CreateOrderRequest, OrderView> for AuditBehavior {
async fn handle(&self, req: CreateOrderRequest, next: Next<CreateOrderRequest, OrderView>)
-> Result<OrderView> { next.run(req).await }
}
svc.add_typed_pipeline::<AuditBehavior, CreateOrderRequest, OrderView>();The behavior only runs for that request/response pair. Short-circuiting is
type-checked: return Rsp without calling [Next::run].
Sourcefn add_typed_pipeline_with<F, Req, Rsp>(self, factory: F) -> Selfwhere
F: Fn(&dyn IServiceResolver) -> Arc<dyn IPipelineBehavior<Req, Rsp>> + Send + Sync + 'static,
Req: Send + 'static,
Rsp: Send + 'static,
fn add_typed_pipeline_with<F, Req, Rsp>(self, factory: F) -> Selfwhere
F: Fn(&dyn IServiceResolver) -> Arc<dyn IPipelineBehavior<Req, Rsp>> + Send + Sync + 'static,
Req: Send + 'static,
Rsp: Send + 'static,
Register a typed pipeline behavior built from a factory (singleton).
The factory receives the DI resolver at construction time, so the
behavior can take constructor dependencies. It runs once per provider;
the resolver is not available inside handle.
Sourcefn add_pipeline<T>(self) -> Self
👎Deprecated since 0.10.0: use add_typed_pipeline::<B, Req, Rsp>() with the typed IPipelineBehavior
fn add_pipeline<T>(self) -> Self
use add_typed_pipeline::<B, Req, Rsp>() with the typed IPipelineBehavior
Register a legacy type-erased pipeline behavior (deprecated).
Requires Default, so it is only usable for behaviors without
dependencies. Use IServiceCollectionExt::add_typed_pipeline for new
code; the erased chain runs outside the typed chain and is removed in 1.0.
Sourcefn add_pipeline_with<F>(self, factory: F) -> Self
👎Deprecated since 0.10.0: use add_typed_pipeline_with(…) with the typed IPipelineBehavior
fn add_pipeline_with<F>(self, factory: F) -> Self
use add_typed_pipeline_with(…) with the typed IPipelineBehavior
Register a legacy type-erased behavior built from a factory (deprecated).
Sourcefn add_hosted_service<T>(self) -> Self
fn add_hosted_service<T>(self) -> Self
Register a hosted service in the DI container as a singleton.
Hosted services are started when the host starts (before accepting requests) and stopped during graceful shutdown.
Analogous to ASP.NET Core’s AddHostedService<T>().
§Example
Host::builder()
.register(|svc| {
svc.add_hosted_service::<DbInitService>()
})
.build()
.run()
.awaitDyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl IServiceCollectionExt for ServiceCollection
impl IServiceCollectionExt for ServiceCollection
fn add_mediator(self) -> ServiceCollection
fn add_request_endpoints(self) -> ServiceCollection
fn add_controllers(self) -> ServiceCollection
fn add_middleware<T>(self) -> ServiceCollection
fn add_typed_pipeline<B, Req, Rsp>(self) -> ServiceCollection
fn add_typed_pipeline_with<F, Req, Rsp>(self, factory: F) -> ServiceCollectionwhere
F: Fn(&dyn IServiceResolver) -> Arc<dyn IPipelineBehavior<Req, Rsp>> + Send + Sync + 'static,
Req: Send + 'static,
Rsp: Send + 'static,
Source§fn add_pipeline<T>(self) -> ServiceCollection
fn add_pipeline<T>(self) -> ServiceCollection
use add_typed_pipeline::<B, Req, Rsp>() with the typed IPipelineBehavior
Source§fn add_pipeline_with<F>(self, factory: F) -> ServiceCollection
fn add_pipeline_with<F>(self, factory: F) -> ServiceCollection
use add_typed_pipeline_with(…) with the typed IPipelineBehavior