pub trait DomainState:
Clone
+ Send
+ Sync
+ 'static {
type Backend: Store + Send + Sync + 'static;
// Required methods
fn domain(&self) -> &Domain;
fn domain_context(&self, ctx: &Context) -> Context<Self::Backend>;
fn mounted(&self, resource: &str) -> Option<Mounted<'_>>;
}domain only.Expand description
Your state, as the ash-domain bridge sees it.
Implement it once, and domain_resource!
writes the Resource and per-operation impls for
every resource you mount — so the same api! that serves a
hand-rolled resource serves a domain-backed one.
impl DomainState for App {
type Backend = InMemoryDataLayer;
fn domain(&self) -> &Domain {
&self.domain
}
fn domain_context(&self, ctx: &Context) -> ash_domain::Context<Self::Backend> {
let mut dctx = ash_domain::Context::new(self.store.clone());
// Carry the request's principal and tenant into the domain, so
// policies see who is asking.
if let Some(tenant) = ctx.tenant() {
dctx.set_tenant(tenant);
}
dctx
}
}A fresh domain context per request is deliberate: it holds the actor and tenant the policies evaluate against, and those belong to one request, not to the process.
Required Associated Types§
Required Methods§
Sourcefn domain_context(&self, ctx: &Context) -> Context<Self::Backend>
fn domain_context(&self, ctx: &Context) -> Context<Self::Backend>
A domain context for one request.
Called once per action. Bind the request’s principal and tenant here —
whatever a policy needs to make its decision — from the JSON:API
Context, which carries them.
Sourcefn mounted(&self, resource: &str) -> Option<Mounted<'_>>
fn mounted(&self, resource: &str) -> Option<Mounted<'_>>
The mounted schema for one resource, by JSON:API type.
Supplies the base path the domain does not know about. Written by
domain_resource! via
MountedSchemas.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".