Replies: 1 comment 1 reply
-
You are using it incorrectly. The factory function Give following code a try and it should work. public register () {
this.container.singleton('MyOrg/Core/FTP', async () => {
const ftpConnection = new PromiseFtp()
return ftpConnection
})
}
public async boot () {
const FtpConnection = this.container.use('MyOrg/Core/FTP')
const configProvider = this.container.use('Adonis/Core/Config')
const ftpConfig = configProvider.get('ftp')
await FtpConnection.connect(ftpConfig)
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi all,
Hope everyone is well 😄
I see we have transitioned to GitHub discussions now!
Had some questions around performing
async
actions inside of a provider setup.I am wrapping the
promise-ftp
library inside theIoC
.Part of the setup for this lib requires some
async
actions to setup.Something like:
I am then using the IoC reference inside of some
ace
commands.I am able to access the
IoC
from myace
commands by adding the following to the command class:However, this is where I run into issues.
It seems
loadApp
only applies to bindings from theregister
method inside the provider. Currently, I am making the bindings inside theboot
methods, as it isasync
- but then I receive errors running the command as it cannot resolve the name from theIoC
.Even with the bindings inside of
boot
, the binding itself has some issues. Using something like:The resulting binding is wrapped inside of a
Promise
and does not allow access to the underlyingftpConnection
object without awaiting it first. I suspect this is due to adding anasync
before the callback function ofthis.container.singleton
If I move
await ftpConnection.connect(ftpConfig)
to the level above,this.container.singleton
then it works but doesn't feel like the 'proper' way of doing the binding.My questions are:
async
actions inside of a provider setup?boot
method inside of myace
commands?Beta Was this translation helpful? Give feedback.
All reactions