Replies: 1 comment
-
It's only early days for me playing around with Adonis but I was just reading about service providers, which I figure is how Lucid integrates itself with Adonis, and that seems to be the case based on this file: https://github.com/adonisjs/lucid/blob/21.x/providers/database_provider.ts It looks like the register method is the key one. Using Lucid's example (with some comments from my guess as to what's going on): register() {
// Registering `Database` class as a singleton in dependency injection,
// and doing custom resolution of its dependencies
this.app.container.singleton(Database, async (resolver) => {
const config = this.app.config.get<DatabaseConfig>('database')
// asking the DI resolver to make us an emitter and logger
const emitter = await resolver.make('emitter')
const logger = await resolver.make('logger')
// Construct the class and return it
const db = new Database(config, logger, emitter)
return db
})
this.app.container.singleton(QueryClient, async (resolver) => {
// This alias is added on the last line
const db = await resolver.make('lucid.db')
return db.connection() as QueryClient
})
this.app.container.alias('lucid.db', Database)
} So I guess for Mongoose (naively) register() {
this.app.container.singleton('mongoose', async (resolver) => {
const config = this.app.config.get<MongooseConfig>('mongoose')
return mongoose.createConnection(config.uri, config.options).asPromise()
})
} And then you'd have to fill out features from there e.g.
|
Beta Was this translation helpful? Give feedback.
0 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 everyone, I am currently looking for a way to integrate Adonis V6 and Mongoose and have some confusion. First of all, the old tutorials are from Adonis V5 which I found quite good but when I integrate it, there are many errors, here is the article link:
https://mcsneaky.ap3k.pro/posts/adonis-v5-provider/
I read some other articles on the original source code that they configure the connection to MongoDB in the start folder and add it to the preloads of adonisrc.ts, but I see it is not the same as the article link above. Please guide me to configure, thank you,
Beta Was this translation helpful? Give feedback.
All reactions