Replies: 1 comment 2 replies
-
|
DatabaseConnection is a wrapper of Arc. So you can clone it as needed. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi
As a Rust beginner, I'm seeking guidance on how to properly manage database connections when integrating SeaORM with a web framework like Salvo. Specifically, I'm confused about whether to use a Singleton pattern or follow a dependency injection (DI) pattern for handling the database connection object (DbConn) in a layered application architecture.
I've reviewed the official examples, but they're often too minimal (e.g., passing DbConn directly in simple handlers). In real-world projects with layered code (e.g., handlers → services → repositories), I'm unsure how to structure this idiomatically in Rust. For example:
Should the DbConn be a global singleton (e.g., using Arc or OnceLock)?
Or should it be explicitly passed through layers via DI (e.g., using Salvo's dependency injection features)?
How to balance ergonomics and ownership/borrowing safety in Rust?
I noticed that the Rust ecosystem emphasizes explicitness and type safety, but I'm struggling to map this to a clean, modular design. Could you provide a recommended pattern or more comprehensive examples for managing database connections in multi-layered applications with SeaORM + Salvo?
Thanks for your guidance!
Beta Was this translation helpful? Give feedback.
All reactions