ModuleDef

izumi.distage.model.definition.ModuleDef
trait ModuleDef extends Module with ModuleDefDSL

DSL for defining module Bindings.

Example:

class Program[F[_]: TagK: Monad] extends ModuleDef {
 make[TaglessProgram[F]]
}

object TryInterpreters extends ModuleDef {
 make[Validation.Handler[Try]].from(tryValidationHandler)
 make[Interaction.Handler[Try]].from(tryInteractionHandler)
}

// Combine modules into a full program
val TryProgram = new Program[Try] ++ TryInterpreters

Singleton bindings:

  • make[X] = create X using its constructor
  • makeTrait[X] = create an abstract class or a trait X using izumi.distage.constructors.TraitConstructor (Auto-Traits feature)
  • makeFactory[X] = create a "factory-like" abstract class or a trait X using izumi.distage.constructors.FactoryConstructor (Auto-Factories feature)
  • make[X].from[XImpl] = bind X to its subtype XImpl using XImpl's constructor
  • make[X].fromTrait[XImpl] = bind X to its abstract class or a trait subtype XImpl, deriving constructor using izumi.distage.constructors.TraitConstructor (Auto-Traits feature)
  • make[X].fromFactory[XImpl] = bind X to its "factory-like" abstract class or a trait subtype XImpl, deriving constructor using izumi.distage.constructors.FactoryConstructor (Auto-Factories feature)
  • make[X].from(myX) = bind X to an already existing instance myX
  • make[X].from { y: Y => new X(y) } = bind X to an instance of X constructed by a given Functoid requesting an Y parameter
  • make[X].from { y: Y @Id("special") => new X(y) } = bind X to an instance of X constructed by a given Functoid, requesting a named "special" Y parameter
  • make[X].from { y: Y => new X(y) }.annotateParameterY = bind X to an instance of X constructed by a given Functoid, requesting a named "special" Y parameter
  • make[X].named("special") = bind a named instance of X. It can then be summoned using Id annotation.
  • make[X].using[X]("special") = bind X to refer to another already bound named instance at key [X].named("special")
  • make[X].fromEffect(X.create[F]: F[X]) = create X using a purely-functional effect X.create in F monad
  • make[X].fromResource(X.resource[F]: Lifecycle[F, X]) = create X using a Lifecycle value specifying its creation and destruction lifecycle
  • make[X].from[XImpl].modify(fun(_)) = Create X using XImpl's constructor and apply fun to the result
  • make[X].from[XImpl].modifyBy(_.flatAp { (c: C, d: D) => (x: X) => c.method(x, d) }) = Create X using XImpl's constructor and modify its Functoid using the provided lambda - in this case by summoning additional C & D dependencies and applying C.method to X

Set bindings:

  • many[X].add[X1].add[X2] = bind a Set of X, and add subtypes X1 and X2 created via their constructors to it. Sets can be bound in multiple different modules. All the elements of the same set in different modules will be joined together.
  • many[X].add(x1).add(x2) = add instances x1 and x2 to a Set[X]
  • many[X].add { y: Y => new X1(y).add { y: Y => X2(y) } = add instances of X1 and X2 constructed by a given Provider function
  • many[X].named("special").add[X1] = create a named set of X, all the elements of it are added to this named set.
  • many[X].ref[XImpl] = add a reference to an already existing binding of XImpl to a set of X's
  • many[X].ref[X]("special") = add a reference to an existing named binding of X to a set of X's

Mutators:

  • modify[X](fun(_)) = add a modifier applying fun to the value bound at X (mutator application order is unspecified)
  • modify[X].by(_.flatAp { (c: C, d: D) => (x: X) => c.method(x, d) }) = add a modifier, applying the provided lambda to a Functoid retrieving X - in this case by summoning additional C & D dependencies and applying C.method to X

Tags:

  • make[X].tagged("t1", "t2) = attach tags to X's binding.
  • many[X].add[X1].tagged("x1tag") = Tag a specific element of X. The tags of sets and their elements are separate.
  • many[X].tagged("xsettag") = Tag the binding of empty Set of X with a tag. The tags of sets and their elements are separate.

Includes:

  • include(that: ModuleDef) = add all bindings in that module into this module

Attributes

See also:

TagK

ModuleDefDSL

Graph
Supertypes
trait TagsDSL
trait Module
trait CachedHashcode
class Object
trait Matchable
class Any

Members list

Concise view

Type members

Inherited classlikes

final class MutationContext

Use this to create utility functions that add bindings mutably to the current module, as opposed to creating new modules and including them.

Use this to create utility functions that add bindings mutably to the current module, as opposed to creating new modules and including them.

Example:

 import distage.{ClassConstructor, Tag, ModuleDef}
 import izumi.distage.model.definition.dsl.ModuleDefDSL

 trait RegisteredComponent
 class RegisteredComponentImpl extends RegisteredComponent

 def addAndRegister[T <: RegisteredComponent: Tag: ClassConstructor](implicit mutateModule: ModuleDefDSL#MutationContext): Unit = {
   new mutateModule.dsl {
     make[T]

     many[RegisteredComponent]
       .weak[T]
   }
 }

 new ModuleDef {
   addAndRegister[RegisteredComponentImpl]
 }

Attributes

Inherited from:
AbstractBindingDefDSL
Graph
Supertypes
class Object
trait Matchable
class Any

Value members

Inherited methods

final override def bindings: Set[Binding]

Attributes

Definition Classes
Inherited from:
ModuleDefDSL
final override def equals(obj: Any): Boolean

Compares the receiver object (this) with the argument object (that) for equivalence.

Compares the receiver object (this) with the argument object (that) for equivalence.

Any implementation of this method should be an equivalence relation:

  • It is reflexive: for any instance x of type Any, x.equals(x) should return true.
  • It is symmetric: for any instances x and y of type Any, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any instances x, y, and z of type Any if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.

If you override this method, you should verify that your implementation remains an equivalence relation. Additionally, when overriding this method it is usually necessary to override hashCode to ensure that objects which are "equal" (o1.equals(o2) returns true) hash to the same scala.Int. (o1.hashCode.equals(o2.hashCode)).

Attributes

that

the object to compare against this object for equality.

Returns:

true if the receiver object is equivalent to the argument; false otherwise.

Definition Classes
ModuleBase -> Any
Inherited from:
ModuleBase
final override def iterator: Iterator[Binding]

Attributes

Definition Classes
Inherited from:
ModuleDefDSL
final def keys: Set[DIKey]

Attributes

Inherited from:
ModuleBase
final override def keysIterator: Iterator[DIKey]

Attributes

Definition Classes
Inherited from:
ModuleDefDSL
final override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns:

a string representation of the object.

Definition Classes
ModuleBase -> Any
Inherited from:
ModuleBase

Inherited fields

final lazy override val hashCode: Int

Calculate a hash code value for the object.

Calculate a hash code value for the object.

The default hashing algorithm is platform dependent.

Note that it is allowed for two objects to have identical hash codes (o1.hashCode.equals(o2.hashCode)) yet not be equal (o1.equals(o2) returns false). A degenerate implementation could always return 0. However, it is required that if two objects are equal (o1.equals(o2) returns true) that they have identical hash codes (o1.hashCode.equals(o2.hashCode)). Therefore, when overriding this method, be sure to verify that the behavior is consistent with the equals method.

Attributes

Returns:

the hash code value for this object.

Inherited from:
CachedHashcode