package definition

  1. Alphabetic
  1. Public
  2. All

Type Members

  1. trait Axis[+MM <: AxisValue] extends AxisBase
  2. sealed trait AxisBase extends AnyRef
  3. sealed trait Binding extends AnyRef
  4. sealed trait BindingTag extends AnyRef
  5. trait BootstrapContextModule extends BootstrapModule
  6. trait BootstrapContextModuleDef extends BootstrapContextModule with ModuleDefDSL
  7. trait BootstrapModule extends ModuleBase
  8. trait BootstrapModuleDef extends BootstrapModule with ModuleDefDSL
  9. trait DIResource[+F[_], Resource] extends DIResourceBase[F, Resource]

    DIResource is a class that captures the effectful allocation of a resource, along with its finalizer.

    DIResource is a class that captures the effectful allocation of a resource, along with its finalizer.

    This can be used to wrap expensive resources.

    Example with DIResource.make:

    def open(file: File): DIResource[IO, BufferedReader] =
      DIResource.make(IO { new BufferedReader(new FileReader(file)) })(in => IO { in.close() })

    Example with inheritance:

    final class BufferedReaderResource(file: File) extends DIResource[IO, BufferedReader] {
      val acquire = IO { new BufferedReader(new FileReader(file)) }
      def release(in: BufferedReader) = IO { in.close() }

    Usage is done via use:

    open(file1).use { in1 =>
      open(file2).use { in2 =>
        readFiles(in1, in2)

    DIResources can be combined into a larger resource via DIResourceBase.flatMap:

    val res: DIResource[IO, (BufferedReader, BufferedReader)] =
      open(file1).flatMap { in1 =>
       open(file2).flatMap { in2 =>
         IO.pure(in1 -> in2)

    Nested resources are released in reverse order of acquisition. Outer resources are released even if an inner use or release fails.

    DIResource can be used in non-FP context with DIResource.Simple it can also mimic Java's initialization-after-construction with DIResource.Mutable

    DIResource is compatible with cats.effect.Resource. Use DIResource.fromCats and DIResource.DIResourceCatsSyntax.toCats to convert back and forth.

    Use DIResource's to specify lifecycles of objects injected into the object graph.


    import cats.effect.IO
    class DBConnection
    class MessageQueueConnection
    val dbResource = DIResource.make(IO { println("Connecting to DB!"); new DBConnection })(_ => IO(println("Disconnecting DB")))
    val mqResource = DIResource.make(IO { println("Connecting to Message Queue!"); new MessageQueueConnection })(_ => IO(println("Disconnecting Message Queue")))
    class MyApp(db: DBConnection, mq: MessageQueueConnection) {
      val run = IO(println("Hello World!"))
    val module = new ModuleDef {
    Injector().produceF[IO](module).use {
      objects =>

    Will produce the following output:

    Connecting to DB!
    Connecting to Message Queue!
    Hello World!
    Disconnecting Message Queue
    Disconnecting DB

    The lifecycle of the entire object graph is itself expressed with DIResource, you can control it by controlling the scope in .use or you can opt-out and use DIResourceBase.acquire and DIResourceBase.release manually.

    See also

    ModuleDef.fromResource: com.github.pshirshov.izumi.distage.model.definition.dsl.ModuleDefDSL.BindDSL.fromResource cats.effect.Resource:

  10. trait DIStageAnnotation extends Annotation with StaticAnnotation
  11. final class Id extends Annotation with DIStageAnnotation

    Annotation for summoning named instances.

    Annotation for summoning named instances.


    val module = new ModuleDef {
    Injector().produce(module).run {
      (five: Int @Id("five"), three: Int @Id("three") =>
        assert(5 == five)
        assert(3 == three)
  12. sealed trait ImplDef extends AnyRef
  13. trait LocatorDef extends AbstractLocator with AbstractBindingDefDSL[BindDSL, SetDSL]
  14. trait Module extends ModuleBase
  15. trait ModuleBase extends AnyRef
  16. trait ModuleDef extends Module with ModuleDefDSL

    DSL for defining module Bindings.

    DSL for defining module Bindings.


    class Program[F[_]: TagK: Monad] extends ModuleDef {
    object TryInterpreters extends ModuleDef {
    // Combine modules into a full program
    val TryProgram = new Program[Try] ++ TryInterpreters

    Singleton bindings:

    • make[X] = create X using its constructor
    • make[X].from[XImpl] = bind X to its subtype XImpl using XImpl's constructor
    • 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 Provider function
    • 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]: Resource[F, X]) = create X using a Resource specifying its creation and destruction lifecycle


    • 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


    • make[X].tagged("t1", "t2) = attach tags to X's binding. Tags can be processed in a special way. See com.github.pshirshov.izumi.distage.roles.RoleId
    • 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.


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




  17. trait ModuleMake[T <: ModuleBase] extends AnyRef
  18. trait StaticDSL extends AnyRef
  19. trait StaticModuleDef extends ModuleDef with StaticDSL
  20. final class With[T] extends Annotation with DIStageAnnotation
  21. trait WithDIAnnotation extends AnyRef

Value Members

  1. object Axis
  2. object Binding
  3. object BindingTag
  4. object Bindings
  5. object BootstrapContextModule
  6. object BootstrapModule
  7. object DIResource
  8. object ImplDef
  9. object LocatorDef
  10. object Module
  11. object ModuleBase
  12. object ModuleMake
  13. object StandardAxis
  14. object StaticDSL extends StaticDSL
  15. object TypeLevelDSL

    Sketch of a DSL that exposes rich type information that can then be picked up and used by a macro to do planning & checks at compile time.

    Sketch of a DSL that exposes rich type information that can then be picked up and used by a macro to do planning & checks at compile time. Note that the DSL is, by necessity, immutable, which is a mismatch with standard ModuleDef.

    A macro analysing syntax trees may instead be employed, to not burden the user with a different version of the syntax. Esp. that ModuleDef syntax is quite simple (but macro will lose user extensions)