Packages

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
  • 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

Multibindings:

  • 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

Tags:

  • 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.

Includes:

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

TagK

Id

ModuleDefDSL

Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ModuleDef
  2. ModuleDefDSL
  3. TagsDSL
  4. IncludesDSL
  5. AbstractBindingDefDSL
  6. Module
  7. ModuleBase
  8. AnyRef
  9. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. abstract type Self <: Module
    Definition Classes
    ModuleModuleBase

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def _initialIncludes: ArrayBuffer[Include]
    Attributes
    protected
    Definition Classes
    IncludesDSL
  5. def _initialTaggedIncludes: ArrayBuffer[IncludeApplyTags]
    Attributes
    protected
    Definition Classes
    IncludesDSL
  6. final def addImplicit[T](name: String)(implicit arg0: reflection.universe.RuntimeDIUniverse.Tag[T], instance: T, pos: CodePositionMaterializer): Unit

    Same as make[T].named(name).from(implicitly[T]) *

    Same as make[T].named(name).from(implicitly[T]) *

    Attributes
    protected
    Definition Classes
    AbstractBindingDefDSL
  7. final def addImplicit[T](implicit arg0: reflection.universe.RuntimeDIUniverse.Tag[T], instance: T, pos: CodePositionMaterializer): Unit

    Same as make[T].from(implicitly[T]) *

    Same as make[T].from(implicitly[T]) *

    Attributes
    protected
    Definition Classes
    AbstractBindingDefDSL
  8. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  9. def bindings: Set[Binding]
    Definition Classes
    ModuleDefDSL
  10. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  11. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  12. final def equals(obj: Any): Boolean
    Definition Classes
    ModuleBase → AnyRef → Any
  13. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  14. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  15. final def hashCode(): Int
    Definition Classes
    ModuleBase → AnyRef → Any
  16. final def include(that: ModuleBase): Unit

    Add all bindings in that module into this module

    Add all bindings in that module into this module

    WON'T add global tags from TagsDSL#tag to included bindings.

    Attributes
    protected
    Definition Classes
    IncludesDSL
  17. final def includeApplyTags(that: ModuleBase): Unit

    Add all bindings in that module into this module

    Add all bindings in that module into this module

    WILL add global tags from TagsDSL#tag to included bindings.

    Attributes
    protected
    Definition Classes
    IncludesDSL
  18. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  19. final def keys: Set[reflection.universe.RuntimeDIUniverse.DIKey]
    Definition Classes
    ModuleBase
  20. final def make[T](implicit arg0: reflection.universe.RuntimeDIUniverse.Tag[T], pos: CodePositionMaterializer): BindDSL[T]
    Attributes
    protected
    Definition Classes
    AbstractBindingDefDSL
  21. final def many[T](implicit arg0: reflection.universe.RuntimeDIUniverse.Tag[T], pos: CodePositionMaterializer): SetDSL[T]

    Multibindings are useful for implementing event listeners, plugins, hooks, http routes, etc.

    Multibindings are useful for implementing event listeners, plugins, hooks, http routes, etc.

    To define a multibinding use .many and .add methods in ModuleDef DSL:

    import cats.effect._, org.http4s._, org.http4s.dsl.io._, scala.concurrent.ExecutionContext.Implicits.global
    import distage._
    
    object HomeRouteModule extends ModuleDef {
      many[HttpRoutes[IO]].add {
        HttpRoutes.of[IO] { case GET -> Root / "home" => Ok(s"Home page!") }
      }
    }

    Multibindings defined in different modules will be merged together into a single Set. You can summon a multibinding by type Set[_]:

    import cats.implicits._, import org.http4s.server.blaze._, import org.http4s.implicits._
    
    object BlogRouteModule extends ModuleDef {
      many[HttpRoutes[IO]].add {
        HttpRoutes.of[IO] { case GET -> Root / "blog" / post => Ok("Blog post ``$post''!") }
      }
    }
    
    class HttpServer(routes: Set[HttpRoutes[IO]]) {
      val router = routes.foldK
    
      def serve = BlazeBuilder[IO]
        .bindHttp(8080, "localhost")
        .mountService(router, "/")
        .start
    }
    
    val objects = Injector().produce(HomeRouteModule ++ BlogRouteModule)
    val server = objects.get[HttpServer]
    
    val testRouter = server.router.orNotFound
    
    testRouter.run(Request[IO](uri = uri("/home"))).flatMap(_.as[String]).unsafeRunSync
    // Home page!
    
    testRouter.run(Request[IO](uri = uri("/blog/1"))).flatMap(_.as[String]).unsafeRunSync
    // Blog post ``1''!
    Attributes
    protected
    Definition Classes
    AbstractBindingDefDSL
    See also

    Guice wiki on Multibindings: https://github.com/google/guice/wiki/Multibindings

  22. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  23. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  24. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  25. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  26. final def tag(tags: BindingTag*): Unit

    Add tags to all bindings in this module, except for included bindings

    Add tags to all bindings in this module, except for included bindings

    Attributes
    protected
    Definition Classes
    TagsDSL
  27. final def toString(): String
    Definition Classes
    ModuleBase → AnyRef → Any
  28. final def todo[T](implicit arg0: reflection.universe.RuntimeDIUniverse.Tag[T], pos: CodePositionMaterializer): Unit

    Create a dummy binding that throws an exception with an error message when it's created.

    Create a dummy binding that throws an exception with an error message when it's created.

    Useful for prototyping.

    Attributes
    protected
    Definition Classes
    ModuleDefDSL
  29. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  30. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  31. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )

Inherited from ModuleDefDSL

Inherited from TagsDSL

Inherited from IncludesDSL

Inherited from Module

Inherited from ModuleBase

Inherited from AnyRef

Inherited from Any

Ungrouped