question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

  1. Defining a class SingletonLocator
export class SingletonLocator {
  public static injector: Injector = undefined;
}
  1. Add in AppModule
export class AppModule {
    constructor(injector: Injector) {
        SingletonLocator.injector = injector;
    }
}
  1. Retrive Singleton in a Component
@Component(..)
export class MyComponent {
 
    private myService: MyService;

   constructor() {
     this.myService = SingletonLocator.get(MyService);
  }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:11
  • Comments:18 (12 by maintainers)

github_iconTop GitHub Comments

9reactions
alxhubcommented, May 4, 2022

This is on our roadmap 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found