The first three posts in this series looked at one crate at a time: strict DI scopes in rust-dix, change tracking in rust-ef, and request-as-endpoint in rust-webx.

This one is about the part none of them could show alone — what happens when a single business operation runs through all three, and the glue that disappears between them.

The glue is not in the handler. It is between the layers.

Ask a .NET team what they rewrite when they move a service to Rust, and they rarely say "the business logic." They say:

  • a route table that drifts from the DTO it points at
  • an Arc<Mutex<DbContext>> because the context needs &mut self
  • a map_*_error function in every layer because three crates define three error types
  • validation rules repeated in code and in OpenAPI annotations

Each piece is small. The problem is that they are four decisions about the same operation, made in four places, reviewed by four people.

Here is one operation — POST /api/orders — assembled from rust-dix, rust-ef and rust-webx.

1. The request is the contract (rust-webx)

The route, the binding rules and the OpenAPI metadata live on the request type, not in a separate routes.rs:

#[derive(WebxRequestMeta)] pub struct CreateOrderRequest { #[fromclaim] pub user: IdentityUser, pub sku: String, pub quantity: i32, } #[post("/api/orders")] impl IRequest<OrderModel> for CreateOrderRequest {} 

#[fromclaim] means "take this from the authenticated identity", so the handler does not parse a token. WebxRequestMeta carries the binding and validation metadata that OpenAPI reads. At compile time, inventory collects the route and the handler registration; Host::build() joins them by TypeId.

If a request has no handler, the host refuses to start. That is the trade — an endpoint cannot ship half-wired.

2. Dependencies are declared, not threaded (rust-dix)

The handler asks for the dependencies it needs. The context is owned, not shared:

#[derive(Inject)] pub struct CreateOrderHandler { #[inject(owned)] pub ctx: DbContext, #[inject] pub clock: Arc<dyn IClock>, } #[handler(inject)] #[async_trait] impl IRequestHandler<CreateOrderRequest, OrderModel> for CreateOrderHandler { async fn handle(&mut self, req: CreateOrderRequest) -> ActionResult<OrderModel> { // ... } } 

#[inject(owned)] is the small detail that removes the lock. DbContext needs &mut self to track changes; Arc<T> only gives &T. An owned context is created inside the request scope, handed to exactly one handler, and dropped when the request ends.

No Arc<Mutex<DbContext>>. No AppState passed down through four function signatures. And if someone registers the context as scoped but resolves it from the root provider, build() returns ScopedFromRootProvider instead of silently creating a shared instance.

That is the point of a container here: not fewer lines of registration, but fewer ways to get ownership wrong.

3. The write is a tracked change, not a full-row UPDATE (rust-ef)

Inside the handler, the ORM call reads like a normal Rust value:

let order = Order::new(req.sku, req.quantity, &req.user.id); self.ctx.set::<Order>().add(order); self.ctx.save_changes().await?; 

For an update, ctx.edit(order, |o| o.patch(req)) followed by detect_changes() writes only the columns that actually changed. A full-row update would overwrite a concurrent edit to a different field — a bug that unit tests rarely catch.

Registration is one line at the composition root:

Host::builder() .register(|svc| { svc.add_dbcontext(|options| options.use_sqlite("data source=app.db")); }) .build() .run() .await?; 

One container owns the context options, so a background worker and a request handler resolve the same provider and the same metadata cache.

4. Errors cross all three layers on one carrier (rust-core)

This is the seam that is invisible until you port a real service.

ActionResult<T> is Result<T, AppError>. AppError is defined in rust-core, a dependency-light crate shared by all three frameworks. Each boundary implements From at its own edge:

  • EFError → AppError in rust-ef
  • RdiError → AppError in rust-dix
  • webx::Error is a re-export of the same carrier, not a second definition

So the handler uses ? for a database error, a DI error and a validation error without a map_err in between. Error::not_found maps to 404; internal error text stays in the operator log and the client sees an empty public_detail().

There is no rust-webx feature in rust-ef and no bridge crate to keep versions aligned. That was a deliberate change in 2.6 — the ORM stays usable in a worker or a CLI.

What I actually stopped writing

Before After
routes.rs + DTO + validation + OpenAPI annotations one request type with WebxRequestMeta
Arc<Mutex<DbContext>> and AppState threading #[inject(owned)] ctx: DbContext
map_ef_error / map_rdi_error in every handler one AppError carrier, ? at the boundary
hand-written DDL and drift between environments entity configuration + migration diff
a scoped service silently shared from the root ScopedFromRootProvider at build()

What it costs

  • MSRV 1.95 and slower incremental builds from proc macros and link-time registration.
  • An opinionated shape: one operation = one request + one handler + one file. A one-line webhook feels heavy.
  • Startup validation: assembly errors surface at boot, which is good in production and annoying in a quick script.
  • A young ecosystem: v2.9.x, few production users, APIs can still move. Use the documented boundaries before betting a service on it.
  • Not for everything: a single-endpoint function or a minimal serverless handler is better served by a small router.

None of that is hidden. The point is that the cost is paid once, at the framework boundary, instead of once per service.

Try one operation, not one service

Do not migrate a whole service to evaluate this. Pick one endpoint with a real state transition.

  1. Write it as a request type plus a handler.
  2. Register one DbContext at the composition root.
  3. Run Host::builder().try_build() and read the assembly report.

The errors you see in the first ten minutes tell you more than a benchmark number.

Repositories:
rust-webx · rust-ef · rust-dix

If you are porting a .NET service: which layer of glue did you most want someone else to write? I would like to know what to tackle next.