Using Models with Commands :: getting IoC Error #1952
-
Hello, I am looking to use some code that I have written in another part of my application that uses one or more models. Example: import { BaseCommand } from '@adonisjs/ace'
import { Kernel } from '@adonisjs/ace'
import { inject } from '@adonisjs/fold'
//import { DatabaseContract } from '@ioc:Adonis/Lucid/Database'
import { ApplicationContract } from '@ioc:Adonis/Core/Application'
import Crawl from "../app/Helpers/Crawl";
@inject([null, null, 'Adonis/Lucid/Database'])
@inject([null, null, 'Adonis/Lucid/Orm'])
export default class CrawlJob extends BaseCommand {
public static needsApplication = true
constructor (app: ApplicationContract, kernel: Kernel, private db: DatabaseContract) {
super(app, kernel)
}
public static settings = {
loadApp: true,
}
/**
* Command Name is used to run the command
*/
public static commandName = 'crawl:job'
/**
* Command Name is displayed in the "help" output
*/
public static description = ''
public async run () {
let crawl = new Crawl({taskId: 1});
try {
await crawl.start();
}catch(e){
console.error(e);
}
console.log(crawl)
}
}
Inside of Crawl, some code is run, and includes a Model, to which I get the following error:
Any ideas how to get past this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Not sure what is inside the public async run () {
const Crawl = (await import('../app/Helpers/Crawl')).default
} Also, there is no need to inject values to the constructor unless you are deciding to provide different values when writing the tests. Simply using imports directly. public async run () {
const Db = (await import('Adonis/Lucid/Database')).default
const Orm = (await import('Adonis/Lucid/Orm')).default
} |
Beta Was this translation helpful? Give feedback.
-
Dude,
In case anyone is having trouble with this going forward. 1. Add this line to your file
2. DONT FORGET TO UPDATE YOUR MANIFEST!👇 👇 👇 👇 👇 👇 👇 👇 👇 👇 👇 👇 👉 ☝️ ☝️ ☝️ ☝️ ☝️ ☝️ ☝️ ☝️ ☝️ ☝️ ☝️ ☝️ Hopefully this helps someone else |
Beta Was this translation helpful? Give feedback.
Dude,
node ace generate:manifest
is KILLING me. The code was already correct.