-
Notifications
You must be signed in to change notification settings - Fork 1
InstanceBindings
Ruedi Steinmann edited this page Mar 24, 2015
·
2 revisions
You can bind a type to a specific instance of that type. This is usually only useful only for objects that don't have dependencies of their own, such as value objects:
bind(String.class)
.annotatedWith(Names.named("JDBC URL"))
.toInstance("jdbc:mysql://localhost/pizza");
bind(Integer.class)
.annotatedWith(Names.named("login timeout seconds"))
.toInstance(10);Avoid using .toInstance with objects that are complicated to create, since it can slow down application startup. You can use an [[@Provides|ProvidesMethods]] method instead.
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