com.escalatesoft.subcut.inject

MutableBindingModule

trait MutableBindingModule extends BindingModule

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:

class SomeBindings extends NewBindingModule (module => {
  import module._
  bind [Trait1] toSingle new Class1Impl
})

// in a test...
SomeBindings.modifyBindings { testBindings =>  // holds mutable copy of SomeBindings
  testBindings.bind[Trait1] toSingle mockClass1Impl  // where the mock has been set up already
  // run tests using the mockClass1Impl
}  // coming out of scope destroys the temporary mutable binding module

Self Type
MutableBindingModule
Linear Supertypes
BindingModule, AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. MutableBindingModule
  2. BindingModule
  3. AnyRef
  4. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. class Bind[T] extends AnyRef

    Inner builder class providing a convenient DSL for configuring the bindings in this mutable binding module.

Value Members

  1. final def !=(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Definition Classes
    AnyRef → Any
  3. def <~(other: BindingModule): Unit

    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
    })
    

  4. final def ==(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  5. def andThen(other: BindingModule): BindingModule

    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.

    other

    another BindingModule to cons with this one. Any duplicates will favor the bindings from this rather than other.

    Definition Classes
    BindingModule
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def bind[T](implicit m: Manifest[T]): Bind[T]

  8. def bindings: Map[BindingKey[_], Any]

    Abstract binding map definition

    Abstract binding map definition

    Definition Classes
    MutableBindingModuleBindingModule
  9. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  10. def deepMapString: Iterable[String]

  11. def ensureNotFrozen(): Unit

  12. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  13. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  14. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  15. def fixed: BindingModule

    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.

    returns

    a new immutable BindingModule

  16. def freeze(): MutableBindingModule

    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.

  17. def frozen: Boolean

    return whether the current state of these bindings is frozen.

  18. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  19. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  20. def inject[T](name: Option[String])(implicit arg0: Manifest[T]): T

    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.

    name

    an optional name to use for the binding match

    returns

    the instance the binding was configured to return

    Definition Classes
    BindingModule
  21. def injectOptional[T](key: BindingKey[T]): Option[T]

    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.

    key

    a BindingKey to use for the lookup

    returns

    Option[T] containing either an instance subtype of T, or None if no matching binding is found.

    Definition Classes
    BindingModule
  22. def injectOptional[T](name: Option[String])(implicit arg0: Manifest[T]): Option[T]

    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.

    name

    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)

    returns

    Option[T] containing either an instance subtype of T, or None if no matching binding is found.

    Definition Classes
    BindingModule
  23. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  24. def listBindings: Iterable[String]

    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.

    Definition Classes
    BindingModule
  25. def mergeWithReplace(other: BindingModule): Unit

    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.

    other

    A BindingModules with bindings to merge and/or replace the bindings in this module.

  26. def modifyBindings[A](fn: (MutableBindingModule) ⇒ A): A

    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.

    fn

    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.

    returns

    the value returned from the provided function.

    Definition Classes
    BindingModule
  27. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  28. final def notify(): Unit

    Definition Classes
    AnyRef
  29. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  30. def pushBindings[A](fn: ⇒ A): A

    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.

    fn

    by-name function that can use and modify the bindings for this module without altering the original.

  31. def replaceBindings(other: BindingModule): Unit

    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.

    other

    the other binding module with which to replace the current bindings.

  32. def showDeepBindings(): Unit

  33. def showMap(): Unit

    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.

  34. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  35. def toString(): String

    Definition Classes
    AnyRef → Any
  36. def unbind[T](symbol: Symbol)(implicit m: Manifest[T]): Option[T]

    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.

    symbol

    A symbol that together with the trait type, identifies the binding to remove.

  37. def unbind[T](name: String)(implicit m: Manifest[T]): Option[T]

    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.

    name

    a String name that together with the trait type, identifies the binding to remove.

  38. def unbind[T]()(implicit m: Manifest[T]): Option[T]

    Unbind a given trait (without name) from the list of bindings.

  39. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  40. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  41. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  42. def withBindingModules(modules: BindingModule*): Unit

    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.

  43. def ~(other: BindingModule): BindingModule

    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.

    other

    another BindingModule to cons with this one. Any duplicates will favor the bindings from this rather than other.

    Definition Classes
    BindingModule
    Annotations
    @inline()

Inherited from BindingModule

Inherited from AnyRef

Inherited from Any

Ungrouped