-
Notifications
You must be signed in to change notification settings - Fork 1
AvoidStaticState
Ruedi Steinmann edited this page Mar 24, 2015
·
2 revisions
Static state and testability are enemies. Your tests should be fast and free of side-effects. But non-constant values held by static fields are a pain to manage. It's tricky to reliably tear down static singletons that are mocked by tests, and this interferes with other tests.
requestStaticInjection() is a crutch. Salta includes this API to ease migration from a statically-configured application to a dependency-injected one. New applications developed with Salta should not use this API.
Although static state is bad, there's nothing wrong with the static keyword. Static classes are okay (preferred even!) and for pure functions (sorting, math, etc.), static is just fine.
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