You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to create a project with Repository Pattern solution.
I create a new Service Provider, and exports this one in my app.js(const providers).
class AppProvider extends ServiceProvider { register() { this.app.singleton('Adonis/Repositories/UsuarioRepository', (app) => { return new UsuarioRepository(); }) this.app.singleton('Adonis/Services/UsuarioService', (app) => { const repo = this.app.use('Adonis/Repositories/UsuarioRepository') return new UsuarioService(repo); }) }
And now I can to inject "UsuarioRepository" into "UsuarioService" via constructor. But I would also like to inject VIA CONSTRUCTOR my "UsuarioService" into Controllers(UsuarioController, for example). How can I do that?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi guys,
I'm trying to create a project with Repository Pattern solution.
I create a new Service Provider, and exports this one in my app.js(const providers).
class AppProvider extends ServiceProvider {
register() {
this.app.singleton('Adonis/Repositories/UsuarioRepository', (app) => {
return new UsuarioRepository();
})
this.app.singleton('Adonis/Services/UsuarioService', (app) => {
const repo = this.app.use('Adonis/Repositories/UsuarioRepository')
return new UsuarioService(repo);
})
}
And now I can to inject "UsuarioRepository" into "UsuarioService" via constructor. But I would also like to inject VIA CONSTRUCTOR my "UsuarioService" into Controllers(UsuarioController, for example). How can I do that?
Beta Was this translation helpful? Give feedback.
All reactions