Inner builder class providing a convenient DSL for configuring the bindings in this mutable binding module.
Convenience form of merge with replace, can be used like this:
Convenience form of merge with replace, can be used like this:
class SomeBindings extends NewBindingModule ({ module => module <~ OtherModule1 // include all bindings from Module1 module <~ OtherModule2 // include all bindings from Module2, overwriting as necessary module.bind[Trait1] toSingle new Class1Impl })
Merge this module with another.
Merge this module with another. The resulting module will include all bindings from both modules, with this module winning if there are common bindings (binding override). If you prefer symbolic operators, ~ is an alias for this.
another BindingModule to cons with this one. Any duplicates will favor the bindings from this rather than other.
Abstract binding map definition
Abstract binding map definition
return an immutable copy of these bindings by creating a new binding module with the bindings taken as an immutable snapshot of the current bindings in this module.
return an immutable copy of these bindings by creating a new binding module with the bindings taken as an immutable snapshot of the current bindings in this module.
a new immutable BindingModule
freeze the current state of this mutable binding module so that it may not be changed further.
freeze the current state of this mutable binding module so that it may not be changed further. This is done by checking the frozen property in the bindings property modifier and is not as safe as using fixed() to obtain a completely immutable copy of the bindings configuration, so fixed() is recommended. However there may be times this approach is preferable. Calling freeze() on a mutable binding module cannot be reversed.
return whether the current state of these bindings is frozen.
Inject for a given class with optional name.
Inject for a given class with optional name. Whatever is bound to the class will be provided. If the name is given, only a matching class/name pair will be used, and it will not fall back to just providing an implementation based only on the class.
an optional name to use for the binding match
the instance the binding was configured to return
Retrieve an optional binding for class T with the given BindingKey, if no binding is available for the binding key, a None will be returned, otherwise the binding will be evaluated and an instance of a subclass of T will be returned.
Retrieve an optional binding for class T with the given BindingKey, if no binding is available for the binding key, a None will be returned, otherwise the binding will be evaluated and an instance of a subclass of T will be returned.
a BindingKey to use for the lookup
Option[T] containing either an instance subtype of T, or None if no matching binding is found.
Retrieve an optional binding for class T with the optional name provided.
Retrieve an optional binding for class T with the optional name provided. If no binding is available with the given class and optional name, a None will be returned, otherwise the binding will be evaluated and an instance of a subclass of T will be returned.
Option[String] name, if present will be matched, if None only class will be used for lookup (note, this also means any named bindings of the same type will not be matched)
Option[T] containing either an instance subtype of T, or None if no matching binding is found.
A convenient way to obtain a string representation of the current bindings in this module.
A convenient way to obtain a string representation of the current bindings in this module. Useful for debugging.
Merge in bindings from another binding module, replacing any conflicts with the new bindings from the other module supplied.
Merge in bindings from another binding module, replacing any conflicts with the new bindings from the other module supplied. May be used to bulk-apply some test configuration onto a mutable copy of the regular bindings.
A BindingModules with bindings to merge and/or replace the bindings in this module.
Provide a mutable copy of these bindings to a passed in function so that it can override the bindings for just the scope of that function.
Provide a mutable copy of these bindings to a passed in function so that it can override the bindings for just the scope of that function. Useful for testing.
a function that takes the new mutable binding copy and may use it within scope. Can return any type, and the any return from the function will be returned from this function.
the value returned from the provided function.
Temporarily push the bindings (as though on a stack) and let the current bindings be overridden for the scope of a provided by-name function.
Temporarily push the bindings (as though on a stack) and let the current bindings be overridden for the scope of a provided by-name function. The binding changes will be popped after execution of the function, restoring the state of the bindings prior to the push.
by-name function that can use and modify the bindings for this module without altering the original.
Replace the current bindings configuration module completely with the bindings from the other module supplied.
Replace the current bindings configuration module completely with the bindings from the other module supplied. This will effectively unbind anything currently bound that is not bound in the new module.
the other binding module with which to replace the current bindings.
A convenient way to list the current bindings in the binding module.
A convenient way to list the current bindings in the binding module. Useful for debugging purposes. Prints to standard out.
Unbind a given trait with the provided symbol from the list of bindings.
Unbind a given trait with the provided symbol from the list of bindings.
A symbol that together with the trait type, identifies the binding to remove.
Unbind a given trait with the provided name from the list of bindings.
Unbind a given trait with the provided name from the list of bindings.
a String name that together with the trait type, identifies the binding to remove.
Unbind a given trait (without name) from the list of bindings.
A convenient way to combine multiple binding modules into one module.
A convenient way to combine multiple binding modules into one module. Just use withBindingModules and
supply a repeated parameter list of BindingModules to merge. The order for conflict resolution is
last in wins, so if you have withBindingModule(ModuleA, ModuleB)
and both ModuleA and ModuleB
bind the same class (and optional name), ModuleB will win.
Merge this module with another.
Merge this module with another. The resulting module will include all bindings from both modules, with this module winning if there are common bindings (binding override). If you prefer non-symbolic methods, "andThen" is an alias for this.
another BindingModule to cons with this one. Any duplicates will favor the bindings from this rather than other.
A mutable binding module. This module is used during construction of bindings configuration with the DSL, but may also be used as a mutable binding module in its own right. Anyone wishing to use the mutable binding module to inject a real system should be aware that they take on all responsibility for threading issues with such usage. For example, tests running in parallel could reconfigure the same binding and cause a race condition which will cause the tests to fail. As such, direct usage of the mutable binding module, particularly in a production environment, is strongly discouraged. Use NewBindingModule instead to ensure immutability and thread safety.
The MutableBindingModule is also provided on a per-function usage by the modifyBindings method on BindingModule. This is the recommended way to have rebindings on a test-by-test basis and is thread safe, as each test gets a new copy of the binding module and will not interfere with others.
An example usage will look like this: