I'm getting frustrated with the repetitive getDb(), getStorage(), and similar function calls in my Hono backend. In other backends I've worked with, I didn’t have to do this as often, which makes me feel like there might be a better way to handle it in Hono.
Ideally, I want my services (like database and storage) to be injected into each request automatically, so I can write functions like:
function xyz(db, storage) { // Use db and storage without having to initialize them inside}
function xyz(db, storage) { // Use db and storage without having to initialize them inside}
function xyz(ctx) { ctx.db; // Already available ctx.storage; // Already available}
function xyz(ctx) { ctx.db; // Already available ctx.storage; // Already available}
without needing to await anything inside these functions because the necessary setup should have already been handled earlier.
Additionally, I'm using Hono embedded inside a SvelteKit app. If possible, I'd like to leverage SvelteKit's locals to pass the already established database connection to Hono, so I don't have to create a new connection each time.
Is there a way to achieve this in Hono while keeping things clean and efficient?