adonisjs / discussion

Discussing about new features and sharing random thoughts: ⚠️ Not every request will be accepted
51 stars 5 forks source link

More service provider functionality #54

Closed shanedaugherty closed 6 years ago

shanedaugherty commented 7 years ago

Hello,

It would be great to be able to add Routes, Models, Controllers, and Migrations through a service provider.

Perhaps this is already possible but I could not find anything in the documentation about it.

thetutlage commented 7 years ago

Yes it is 100% possible. If you look closely, Controllers, Models and almost everything is an IoC container namespace, it does not matter where the file for that namespace is, it can be inside your own project or inside a package. For example

class MyController {
  profile () {
  }
}

ioc.bind('MyController', function () {
  return new MyController()
})

Inside your routes.

Route.get('me', '@provider:MyController.profile')
ghost commented 7 years ago

I had a feeling that was the case. Thank you for taking the time to reply.