DEV Community

Cover image for Avoiding fat controllers in AdonisJs

Avoiding fat controllers in AdonisJs

Michael Z on January 01, 2019

Originally posted at michaelzanggl.com. Subscribe to my newsletter to never miss out on new content. Today we will take a look at controllers an...
Collapse
 
xqsit profile image
Manikandan B

What about module.exports = new ArticleService() instead of calling it on constructor?

Really great article. Thanks! :)

Collapse
 
michi profile image
Michael Z

Then you would always get the same instance of ArticleService. In this case it would maybe not be a problem, but it would be inconsistent with the rest of the application I'd assume. But you are definitely right that it was not the best decision to simply new it up in the constructor. A better way would be to use Adonis' automatic dependency injection so it gets newed up automatically and is easy to fake.

Collapse
 
lortnok2 profile image
Lortnok2

Interesting article. When will the Post Controller refactoring come out ?

Collapse
 
michi profile image
Michael Z

Thanks, I've just starting writing the module for it.