Can't add MongoKitten database as a service in Vapor
dannymout opened this issue · comments
I'm trying to add a MongoKitten/MongoDB database as a service in Vapor, and I can't seem to get it to work as shown in the readme.
/// Called before your application initializes.
public func configure(_ config: inout Config, _ env: inout Environment, _ services: inout Services) throws {
...
// Register database
let connectionURI = "mongodb://localhost:27017/test"
services.register { container -> MongoKitten.Database in
return try MongoKitten.Database.lazyConnect(connectionURI, on: )
}
...
}
From here, I cannot access container
as a Container
type, so I can't use container.eventLoop
.
Try this
extension MongoKitten.Database: Service {}
//Inside configure
services.register(MongoKitten.Database.self) { container in
return try MongoKitten.Database.lazyConnect(settings: mongoSettings, on: container.eventLoop)
}
@Andrewangeta Adding that extension seemed to fix it, thanks!