Injector. Also see @Singleton.
Introduction from the author: Implementation of this class seems unreasonably complicated at the first sight. I fully agree with you, that the beast below is very complex and it's hard to reason on how does it work or not. Still I want to assure you that hundreds(?) of hours were thrown into making this code simple, while still maintaining Singleton contract.
Anyway, why is it so complex? Singleton scope does not seem to be that unique.
scope(Key, Provider), CycleDetectingLock
| Modifier and Type | Field and Description |
|---|---|
| private static final CycleDetectingLock. | cycleDetectingLockFactory
Allows us to detect when circular proxies are necessary. |
| private static final Object | NULL
A sentinel value representing null. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public <T> Provider | scope(final Key<T>
binding key key, final Provider<T> locates an instance when one doesn't already exist in this scope. creator)Implements com.
|
| public String | toString()
Overrides java. Implements com. |
| cycleDetectingLockFactory | back to summary |
|---|---|
| private static final CycleDetectingLock. Allows us to detect when circular proxies are necessary. It's only used during singleton instance initialization, after initialization direct access through volatile field is used. NB: Factory uses | |
| NULL | back to summary |
|---|---|
| private static final Object NULL A sentinel value representing null. | |
| SingletonScope | back to summary |
|---|---|
| public SingletonScope() | |
| scope | back to summary |
|---|---|
| public <T> Provider Implements com. Provides singleton scope with the following properties:
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Implements com. Doc from com. A short but useful description of this scope. For comparison, the standard scopes that ship
with guice use the descriptions
| |