Package

com.escalatesoft.subcut

inject

Permalink

package inject

Created by IntelliJ IDEA. User: Dick Wall Date: 5/5/11 Time: 10:06 AM

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. inject
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Visibility
  1. Public
  2. All

Type Members

  1. class AnnotationsInjectPlugin extends Plugin

    Permalink

    Created by IntelliJ IDEA.

    Created by IntelliJ IDEA. User: dick Date: 7/25/11 Time: 3:16 PM To change this template use File | Settings | File Templates.

  2. trait AutoInjectable extends Injectable

    Permalink

    AutoInjectable is identical to Injectable except that if you are using the compiler plugin, the implicit bindingModule parameter will be automatically filled in for you.

    AutoInjectable is identical to Injectable except that if you are using the compiler plugin, the implicit bindingModule parameter will be automatically filled in for you. It is provided as a convenient boilerplate buster but is distinct from Injectable because sometimes you want to mark something as Injectable but keep the injection abstract until later.

  3. class BindingException extends Exception

    Permalink

    Thrown if there is an issue with a binding, for example, no matching binding for a given Binding key.

  4. abstract class BindingId extends AnyRef

    Permalink

    Created with IntelliJ IDEA.

    Created with IntelliJ IDEA. User: dick Date: 1/1/13 Time: 2:05 PM An abstract superclass for BindingId definitions as objects - used for easy, typesafe and code completion compatible binding names.

    E.g.

    object MainDB extends BindingId
    ...
    
    bind [Db] idBy BindingId toSingle new SqlDB
  5. trait BindingModule extends AnyRef

    Permalink

    The main BindingModule trait.

    The main BindingModule trait. Not intended to be used directly, instead extend NewBindingModule with a function to create the bindings (recommended - the result will be immutable) or a MutableBindingModule (not recommended unless you know what you are doing and take on the thread safety responsibility yourself).

  6. trait BoundToModule extends AnyRef

    Permalink

    A trait that can be used to provide the cake-like ability to mix in a trait upon instance creation rather than using the implicit parameter.

    A trait that can be used to provide the cake-like ability to mix in a trait upon instance creation rather than using the implicit parameter. This is less flexible but may still be desired by some developers. To use it, simply create a new trait that extends this one, and provide the definition of bindingModule to point to a suitable BindingModule. You can then mix this trait in to any other class or new composition to provide the injector bindings.

  7. class Inject extends Annotation with StaticAnnotation

    Permalink

    Created by IntelliJ IDEA.

    Created by IntelliJ IDEA. User: dick Date: 7/25/11 Time: 2:40 PM To change this template use File | Settings | File Templates.

  8. trait Injectable extends AnyRef

    Permalink

    The trait that provides dependency injection features for a class or object.

    The trait that provides dependency injection features for a class or object. To use this trait, Mix it in to the class or object definition, and then define the abstract bindingModule which holds the bindings to be used. There are several ways to provide these binding modules: simple val override in the class, mixing in a trait that defines the bindingModule (see BoundToModule), a constructor parameter or, perhaps most flexibly, an implicit constructor parameter in a curried parameter list. This last option can provide flexible and mostly invisible bindings all the way down an object instance creation chain.

  9. trait MutableBindingModule extends BindingModule

    Permalink

    A mutable binding module.

    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
  10. class NewBindingModule extends BindingModule with Serializable

    Permalink

    A class to create a new, immutable, binding module.

    A class to create a new, immutable, binding module. In order to work, the constructor of this class takes a function to evaluate, and passes this on to a bindings method which can be used to resolve the bindingModule using the function on demand. The binding module loaned to the passed in function is mutable, allowing the convenient DSL to be used, then the bindings are copied to an immutable class upon exit of the bindings evaluation.

    To use this class:

    class ProductionBindings extends NewBindingModule(module => {
       import module._   // for convenience
       bind [DBLookup] to moduleInstanceOf [MySQLLookup]
       bind [WebService] to newInstanceOf [RealWebService]
       bind [Int] identifiedBy 'maxPoolSize toSingle 10   // could also use idBy instead of identifiedBy
       bind [QueryService] toProvider { implicit module => new SlowInitQueryService }
    })
    Annotations
    @SerialVersionUID()

Value Members

  1. object NewBindingModule extends Serializable

    Permalink

    A companion object holding a convenience method to create new binding modules on the fly when passed a function from MutableBindingModule to unit.

    A companion object holding a convenience method to create new binding modules on the fly when passed a function from MutableBindingModule to unit.

    to use this class:

    import NewBindingModule._
    implicit val bindingModule = newBindingModule { module =>
       import module._
       bind [DBLookup] toProvider { module => new MySQLLookup(module) } // could use implicit module => instead
       bind [WebService] to newInstanceOf [RealWebService]
       bind [Int] identifiedBy 'maxPoolSize toSingle 10   // could also use idBy instead of identifiedBy
       bind [QueryService] toSingle { new SlowInitQueryService }
    }
  2. implicit def bindingIdToString(bindingId: BindingId): String

    Permalink

    An implicit conversion from BindingId subclasses to String type, so that objects that extend BindingId can be used as Binding identifiers both for binding and for injection.

    An implicit conversion from BindingId subclasses to String type, so that objects that extend BindingId can be used as Binding identifiers both for binding and for injection.

    bindingId

    a sub-object of BindingId

    returns

    String short name of Binding object class

  3. val injected: Option[Nothing]

    Permalink

    Package definition to provide an injected value that indicates the default value for a constructor parameter is to be injected.

    Package definition to provide an injected value that indicates the default value for a constructor parameter is to be injected. This is just a name for None and is typed to Option[Nothing] so it should be possible to use it as a missing default for any constructor injected parameter. Should be used in conjunction with Injectable.injectIfMissing

  4. def moduleInstanceOf[T](implicit m: Manifest[T]): ClassSingleModuleProvider[T]

    Permalink

    Convenience method to create a new reflective instance provider for the given class.

    Convenience method to create a new reflective instance provider for the given class. When bound, each request for the bound item will return the same instance for the current bindingModule. Calls with new bindingModules will get a new instance which will also be a singleton within that bindingModule.

    T

    the class to create new instances of

    m

    implicit manifest of class to create instances of

    returns

    a new class instance provider

  5. def newInstanceOf[T](implicit m: Manifest[T]): ClassInstanceProvider[T]

    Permalink

    Convenience method to create a new reflective instance provider for the given class.

    Convenience method to create a new reflective instance provider for the given class. When bound, each request for the bound item will create a new instance reflectively and return that new instance. Instances must not take any constructor parameters other than (optionally) the bindingModule.

    T

    the class to create new instances of

    m

    implicit manifest of class to create instances of

    returns

    a new class instance provider

  6. package util

    Permalink

Inherited from AnyRef

Inherited from Any

Ungrouped