Providing values to the constructor/factory
See original GitHub issueHello,
maybe I am getting something wrong, but I am looking for a way to provide a parameter to the constructor. My use case is, that I would like to inject a logger, that should be instantiated with a module name, e.g. const logger = new Logger('moduleX');
That I would like to change to work like this
class ModuleX {
@Inject
private logger: Logger;
public doSmth () {
this.logger.info('log something');
}
}
Obviously this is not supported and therefor I assume not a good practice, or am I missing something?
thank you!
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How to assign value to a variable inside factory constructor ...
Problem: In factory constructor, when I get data , I also need to initialise downloadUrl field but I can't do that in factory...
Read more >Java Constructors vs Static Factory Methods - Baeldung
Learn about static factory methods in Java and why they're sometimes preferred over constructors for instantiating and initializing objects.
Read more >Dart/Flutter Constructors tutorial with examples - BezKoder
We can use the factory keyword for a constructor that return an object instead of creating a new instance. class Customer { String...
Read more >Difference Between Constructor and Static Factory Method in ...
The static factory method has names that clarify the code, unlike the constructors. In the static factory method, we do not need to...
Read more >Replace constructor with factory method | IntelliJ IDEA ...
The Replace Constructor With Factory Method refactoring lets you hide a constructor and replace it with a static method which returns a new ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@pleerock How about situation when we have to pass data dynamically from external source? Can we do it this way?
Depend on what
loggeris. If it is a service then it should look something like this:Else, if logger not a service then you can simply do: