Services
An AppService
is a long-running, persistent
task that's the primary way to add functionality to your app. Roadster provides some AppService
s, such
as HttpService
,
SidekiqWorkerService
,
and the general FunctionService
.
Registering a service
In order to run a service in your app, it needs to be registered with the service registry.
use roadster::app::context::AppContext;
use roadster::service::http::service::HttpService;
type App = RoadsterApp<AppContext>;
fn build_app() -> App {
RoadsterApp::builder()
// Use the default `AppContext` for this example
.state_provider(|context| Ok(context))
.add_service_provider(move |registry, state| {
Box::pin(async move {
registry
.register_builder(HttpService::builder(Some("/api"), state))
.await?;
Ok(())
})
})
.build()
}