Skip to content

E_IOC_LOOKUP_FAILED: Cannot resolve "Adonis/Lucid/Orm" namespace from the IoC Container #3458

Answered by tomgobich
alancwoo asked this question in Help
Discussion options

You must be logged in to vote

Yes, services are a great way to simplify controller logic and a great place to house methods that need to be used across multiple controllers. I typically don't register an IOC namespace for my services, I just import them in the controllers I need them.

There are a few ways you can do this. The way you're going about it is great if you need the same instance of the service class to be used for every single request your server receives. If that's not a requirement for you below are some alternatives.

Using Static Methods

// app/Services/PostService.ts

export default class PostService {
  public static async getRecentPosts(numPosts) {
    // fetch posts ...
  }
}

// app/Controllers/Http…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@alancwoo
Comment options

@tomgobich
Comment options

@alancwoo
Comment options

@tomgobich
Comment options

Answer selected by alancwoo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants