-
Notifications
You must be signed in to change notification settings - Fork 1
InjectionPointSpecificInjections
Ruedi Steinmann edited this page Mar 27, 2015
·
1 revision
creating instances that depend where they are injected into
Salta allows the creation of instances which depend on where they are injected. Remember that bindings cannot be injection point specific, since they might be reused for different injection points due to scoping.
Thus the instance is created by a CreationRule, which receives a CoreDependencyKey and can return a function creating a Supplier. Register the rule using bindCreationRule(...).
The canonical example is the injection of a logger, initialized with the name of the class it was injected into:
@Override
protected void configure() throws Exception {
bindCreationRule(new CreationRuleImpl(
CoreDependencyKey.rawTypeMatcher(Logger.class),
key -> () -> Logger.getLogger(key.getRawType().getName())
));
}The Salta wiki. It was copied from the Guice Wiki and adapted to Salta.
- Home
- Why Dependency Injection?
- Getting Started
- Bindings
- Scopes
- Injections
- Injecting Providers
- AOP
- Speed
- Frequently Asked Questions
- Extending Salta
- Internals
- Best Practices
- Community