Feature request : Allow properties Injection
See original GitHub issue🚀 feature request
[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
[ ] Other... Please describe:
Description
Give the possibility to inject somthing without using constructor
Current behavior
All the dependencies must be injected in constructor:
Expected behavior
Add new annotation @Autowire for the property which can be present with @Optional, for example:
export class MyClass {
  @Autowire
  private mainClass: MainClass;
}
Current solution
- Defining a class SingletonLocator
export class SingletonLocator {
  public static injector: Injector = undefined;
}
- Add in AppModule
export class AppModule {
    constructor(injector: Injector) {
        SingletonLocator.injector = injector;
    }
}
- Retrive Singleton in a Component
@Component(..)
export class MyComponent {
 
    private myService: MyService;
   constructor() {
     this.myService = SingletonLocator.get(MyService);
  }
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:11
- Comments:18 (12 by maintainers)
 Top Results From Across the Web
Top Results From Across the Web
Feature Request - Allow properties to be resolved dynamically ...
This request comes after a good chat with @alvarosanchez. It seems that the PropertySource resolution works as follow (and I apologize if I ......
Read more >Core Features - Spring
It is possible to enable admin-related features for the application by specifying the spring.application.admin.enabled property. This exposes the ...
Read more >Accessing application properties with Spring Boot properties API
Spring Boot @ConfigurationProperties has a few limitations. For instance, Map injection is not supported. Consider using Mapping configuration to objects.
Read more >How can I inject a property value into a Spring Bean which ...
Because PersonDaoImpl does not feature in the Spring XML file (it is picked up from the classpath via annotations). I've got as far...
Read more >Feature Flags with Spring - Baeldung
Learn how feature flags can help you to enable or disable different ... We'll discuss various scenarios that might require feature flagging ...
Read more > Top Related Medium Post
Top Related Medium Post
No results found
 Top Related StackOverflow Question
Top Related StackOverflow Question
No results found
 Troubleshoot Live Code
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
Top Related Reddit Thread
No results found
 Top Related Hackernoon Post
Top Related Hackernoon Post
No results found
 Top Related Tweet
Top Related Tweet
No results found
 Top Related Dev.to Post
Top Related Dev.to Post
No results found
 Top Related Hashnode Post
Top Related Hashnode Post
No results found

This is on our roadmap 😃
@mascoun https://www.npmjs.com/package/@angular-ru/autowired