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
The ES-module with definition of ApiService class depends on infrastructure layer: your library brandi and on the module structue: TOKENS.
Just move this line to the composition root and everything becomes well again:
import{DependencyModule,injected}from'brandi';import{TOKENS}from'../tokens';import{ApiService}from'./ApiService';exportconstapiModule=newDependencyModule();apiModule.bind(TOKENS.apiKey).toConstant('#key9428');injected(ApiService,TOKENS.apiKey);// << this code should be hereapiModule.bind(TOKENS.apiService).toInstance(ApiService).inTransientScope();
All dependency resolution rules should be placed in single place: composition root (see: Dependency Injection Principles, Practices, and Patterns by Steven van Deursen and Mark Seemann)
And if you are going to move it to the composition root, just add the inject parameter to the container methods: toFactory and toInstance:
This is actually what I'm doing in my library usage of brandi. I'm exporting a set of tokens, a dependency module, and a default set of injected() registrations that can be used collectively or rebound by the consuming application.
Hey, @vovaspace
This line violates Dependcy Inversion Principle:
brandi/docs/reference/dependency-modules.md
Line 79 in 08a4748
The ES-module with definition of
ApiService
class depends on infrastructure layer: your librarybrandi
and on the module structue:TOKENS
.Just move this line to the composition root and everything becomes well again:
All dependency resolution rules should be placed in single place: composition root (see: Dependency Injection Principles, Practices, and Patterns by Steven van Deursen and Mark Seemann)
And if you are going to move it to the composition root, just add the
inject
parameter to the container methods:toFactory
andtoInstance
:The text was updated successfully, but these errors were encountered: