scaldi
package scaldi
Scaldi - is Scala dependency injection library. Basically Scala already have everything you need for dependency injection. But still some things can be made easier. Goal of the project is to provide more standard and easy way to make dependency injection in Scala projects consuming power of the Scala language. With Scaldi you can define your application modules in pure Scala without any annotations or XML.
For more information see: http://scaldi.org
- Alphabetic
- By Inheritance
- scaldi
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
- case class AndCondition(conditions: List[Condition]) extends Condition with Product with Serializable
- class BindHelper[R] extends CanBeIdentified[BindHelper[R]] with CanBeConditional[BindHelper[R]]
-
trait
Binding extends Identifiable
Binding is defined in a
Module
as Type -> instance relationship (sometimes with additional identifiers).Binding is defined in a
Module
as Type -> instance relationship (sometimes with additional identifiers). I can be injected in classes where implicitInjector
is available. Binding can be defined (containing a value) or undefined. - class BindingException extends RuntimeException
- case class BindingLifecycle[-T](initialize: Option[(T) ⇒ Unit] = None, destroy: Option[(T) ⇒ Unit] = None) extends Product with Serializable
-
trait
BindingWithLifecycle extends Identifiable
Bindings with lifecycle may have initialization and destruction handlers
- class BoundHelper[D] extends CanBeIdentified[BoundHelper[D]] with CanBeConditional[BoundHelper[D]] with CanHaveLifecycle[BoundHelper[D], D]
-
class
ByWord extends AnyRef
Helper class to make injection with default value more readable.
- trait CanBeConditional[R] extends AnyRef
- trait CanBeIdentified[R] extends AnyRef
-
trait
CanBeIdentifier[T] extends AnyRef
Implementation to implicitly transform
T
class to anIdentifier
Implementation to implicitly transform
T
class to anIdentifier
- T
type that should be transformed to an Identifier
- Annotations
- @implicitNotFound( ... )
-
trait
CanCompose[-A, -B, +R] extends AnyRef
Typeclass that will handle the composition of different injectors
Typeclass that will handle the composition of different injectors
- A
type of the first injector in the composition
- B
type of the second injector in the composition
- R
type of the resulting injector in the composition
- Annotations
- @implicitNotFound( ... )
- trait CanHaveLifecycle[H, D] extends AnyRef
- trait Condition extends AnyRef
-
class
DynamicModule extends WordBinder with InjectorWithLifecycle[DynamicModule] with OpenInjectable with MutableInjectorUser with ShutdownHookLifecycleManager
Same as module, but with accessible
Injectable
's methods. -
trait
Freezable extends AnyRef
Trait for injectors that are freezable i.e.
Trait for injectors that are freezable i.e. may no longer be modified from e certain point
-
trait
Identifiable extends AnyRef
Entities that extend
Identifiable
can be identified using Scaldi identifiers.Entities that extend
Identifiable
can be identified using Scaldi identifiers. They can also contain conditions. -
class
IdentifiedWord[+T] extends AnyRef
Helper class to make injection by identifier more readable.
Helper class to make injection by identifier more readable.
- T
type of the dependency being injected
-
trait
Identifier extends AnyRef
Used to identify a binding.
Used to identify a binding. If you have two bindings of the same type (like
String
bindings), the identifiers may be used to identify and to inject the right one -
trait
ImmutableInjector extends Injector
Immutable injectors that don't have any lifecycle associated with it.
-
class
ImmutableInjectorAggregation extends Injector
The result of the composition of two or more of the immutable injectors
-
class
ImmutableWrapper extends Injector with ImmutableInjector
A very simple implementation of an injector that just delegates the binding lookup to some other injector.
A very simple implementation of an injector that just delegates the binding lookup to some other injector. This will protect the lifecycle of the delegated injector from any changes. It is useful in a case of a scoped binding: if you want to use the injector in a composition, but don't want the composition's lifecycle to influence it. In that case, before creating the composition wrap the injector into the
ImmutableWrapper
. -
trait
Initializeable[I] extends Freezable
Trait for injectors that are initializeable i.e.
Trait for injectors that are initializeable i.e. have initialization phase
- I
type for initializeable injector
-
case class
InjectConstraints[+T](default: Option[() ⇒ T] = None, initialIdentifiers: List[Identifier] = Nil) extends Product with Serializable
A wrapper for a default value for the injection and for its identifiers.
A wrapper for a default value for the injection and for its identifiers.
It is here to make injection constraints look like natural language.
- T
type of the dependency being injected
- default
default value for injected instance. It would be used if biding is not found in the
Injector
.- initialIdentifiers
identifiers
-
class
InjectException extends RuntimeException
Custom exception for injectors
-
trait
Injectable extends Wire
Provides injection DSL.
Provides injection DSL. You can extend it in your classes in order to use inject methods.
The only responsibility of this trait is to provide you with inject function (so it just provides nice syntax for injecting dependencies).
In order to actually find and inject dependencies,
inject
method always takes an implicit parameter of typeInjector
.Example:
Application (implicit inj: Injector) extends Injectable { protected val db = inject [Database] // database can now be used as an instance of Database class` }
-
trait
Injector extends AnyRef
A base entity that encapsulates the binding lookup mechanism
-
trait
InjectorWithLifecycle[I <: InjectorWithLifecycle[I]] extends Injector with Initializeable[I] with MutableInjector
Trait for injectors that have lifecycle
Trait for injectors that have lifecycle
- I
type for initializeable injector
-
case class
LazyBinding(createFn: Option[() ⇒ Any], identifiers: List[Identifier] = Nil, condition: Option[() ⇒ Condition] = None, lifecycle: BindingLifecycle[Any] = BindingLifecycle.empty) extends BindingWithLifecycle with Product with Serializable
Binding that is initialized on on first use and never changes afterwards.
Binding that is initialized on on first use and never changes afterwards.
- createFn
function that creates and returns value that will be associated with binding
- identifiers
binding's identifiers (empty by default)
- condition
binding's conditions (empty by default)
- lifecycle
binding's lifecycle (empty by default)
- trait LifecycleManager extends AnyRef
- trait LowPriorityImmutableInjectorComposition extends LowPriorityMutableInjectorComposition
- trait LowPriorityMutableInjectorComposition extends AnyRef
-
trait
Module extends WordBinder with InjectorWithLifecycle[Module] with Injectable with MutableInjectorUser with ShutdownHookLifecycleManager
Module is a place where you declare your bindings.
Module is a place where you declare your bindings. It's also the most common injector that you can use in most cases. It's a mutable injector so it can have a lifecycle and it also provides nice DSL for the bindings.
Module is an Injectable instance thanks to that you can inject other dependencies in module's bindings.
-
trait
MutableInjector extends Injector
Mutable injectors that have a lifecycle associated with them.
-
class
MutableInjectorAggregation extends InjectorWithLifecycle[MutableInjectorAggregation] with MutableInjectorUser with ShutdownHookLifecycleManager
The result of the composition of two or more of the mutable injectors
-
trait
MutableInjectorUser extends MutableInjector
Contains implicit reference to injector: the final injector composition which is used by inject.
Contains implicit reference to injector: the final injector composition which is used by inject. Injector aggregation will set it during the initialization phase
-
case class
NonLazyBinding(createFn: Option[() ⇒ Any], identifiers: List[Identifier] = Nil, condition: Option[() ⇒ Condition] = None, lifecycle: BindingLifecycle[Any] = BindingLifecycle.empty) extends BindingWithLifecycle with Product with Serializable
Binding that is initialized at the Injector initialization phase (normally during an application startup) and never changes afterwards.
Binding that is initialized at the Injector initialization phase (normally during an application startup) and never changes afterwards.
- createFn
function that creates and returns value that will be associated with binding
- identifiers
binding's identifiers (empty by default)
- condition
binding's conditions (empty by default)
- lifecycle
binding's lifecycle (empty by default)
- case class NotCondition(condition: Condition) extends Condition with Product with Serializable
-
trait
OpenInjectable extends Injectable
Exactly the same as Injectable trait, but with all methods made public
- case class OrCondition(conditions: List[Condition]) extends Condition with Product with Serializable
-
class
PropertiesInjector extends RawInjector
Used to look for simple bindings in supplied properties (hash table)
-
case class
ProviderBinding(createFn: () ⇒ Any, identifiers: List[Identifier] = Nil, condition: Option[() ⇒ Condition] = None, lifecycle: BindingLifecycle[Any] = BindingLifecycle.empty) extends BindingWithLifecycle with Product with Serializable
Binding that is initialized on every injection with createFn function.
Binding that is initialized on every injection with createFn function.
- createFn
function that creates and returns value that will be associated with binding
- identifiers
binding's identifiers (empty by default)
- condition
binding's conditions (empty by default)
- lifecycle
binding's lifecycle (empty by default)
-
case class
RawBinding(value: Any, identifiers: List[Identifier]) extends Binding with Product with Serializable
Binding with a raw value, not converted to any specific type (value from system properties, configuration, etc.).
Binding with a raw value, not converted to any specific type (value from system properties, configuration, etc.).
- value
value of the binding
- identifiers
identifiers defining the binding
-
trait
RawInjector extends Injector
Abstract
Injector
implementation that may be extended by other injectors that get values from specific source (command line, typesafe config, properties, etc.) -
case class
RequiredIdentifier(delegate: Identifier, isRequired: Boolean) extends Identifier with Product with Serializable
Wraps a delegated
Identifier
as a required or not requiredWraps a delegated
Identifier
as a required or not required- delegate
delegated
Identifier
- isRequired
true if the wrapped identifier should be required
- trait ShutdownHookLifecycleManager extends LifecycleManager
-
case class
SimpleBinding[T](boundValue: Option[() ⇒ T], identifiers: List[Identifier] = Nil, condition: Option[() ⇒ Condition] = None, cacheable: Boolean = false, eager: Boolean = false) extends Binding with Product with Serializable
Binding that only contains a value.
Binding that only contains a value. As it is just a fixed value, no lifecycle is needed
- T
binding's type
- boundValue
binding's value
- identifiers
binding's identifiers (empty by default)
- condition
binding's conditions (empty by default)
- cacheable
if binding should be cacheable (false by default)
- eager
if binding is eager (non lazy) (false by default)
-
class
SimpleContainerInjector extends MutableInjectorUser with InjectorWithLifecycle[SimpleContainerInjector] with ShutdownHookLifecycleManager
Container that transforms a list of bindings into a valid
Injector
-
case class
StringIdentifier(str: String) extends Identifier with Product with Serializable
Defines an identifier from a
String
Defines an identifier from a
String
- str
String
that will be the identifier
- case class SysPropCondition(name: String, value: Option[String] = None, dynamic: Boolean = false) extends Condition with Product with Serializable
-
final
class
TypeTagIdentifier extends Identifier
Identifier created from any Scala type
-
class
TypesafeConfigInjector extends RawInjector
Injector with bindings found in supplied typesafe configuration
- trait Wire extends AnyRef
- class WireBuilder extends AnyRef
- trait WordBinder extends AnyRef
- case class WordBindingProvider[T](bindingFn: (List[Identifier], Option[() ⇒ Condition], BindingLifecycle[Any]) ⇒ BindingWithLifecycle) extends Product with Serializable
-
trait
BindingProvider extends AnyRef
- Annotations
- @deprecated
- Deprecated
(Since version 0.5) BindingProvider is deprecated and will be removed soon. As an alternative you can use
ImmutableWrapper
injector to define an immutability boundary in composition or create your own injector that is marked asImmutableInjector
.
-
trait
ReflectionBinder extends AnyRef
- Annotations
- @deprecated
- Deprecated
(Since version 0.5) ReflectionBinder is deprecated and will be removed soon. As an alternative you can use
WordBinder
or create your own injector that is marked asImmutableInjector
.
-
trait
StaticModule extends ReflectionBinder with ImmutableInjector with Injectable
- Annotations
- @deprecated
- Deprecated
(Since version 0.5)
Value Members
-
object
Args
Factory for creating injector from command line arguments
- object Binding
- object BindingLifecycle extends Serializable
- object BindingWithLifecycle
- object CanBeIdentifier
- object Condition
- object DynamicModule
- object Identifier
- object ImmutableWrapper
-
object
Injectable extends OpenInjectable
Companion object of Injectable which can be just imported in contrast to Injectable trait which always need to be extended.
Companion object of Injectable which can be just imported in contrast to Injectable trait which always need to be extended. After importing it, you can use an injection DSL without extending the trait.
Example:
import scaldi.Injectable._ val database = inject [Database]
- object Injector extends LowPriorityImmutableInjectorComposition
-
object
NilInjector extends ImmutableInjector
Empty injector, used for injector combination or as a filler where injector is required, but there are no bindings.
-
object
PropertiesInjector
Factories to handle different type of properties' source.
-
object
SystemPropertiesInjector extends RawInjector
Used to look up for simple bindings in system properties.
- object TypeTagIdentifier
-
object
TypesafeConfigInjector
Factories to handle different type of Typesafe config's source.
- object WireBuilder