MakeDSLBase

izumi.distage.model.definition.dsl.ModuleDefDSL$.MakeDSLBase
See theMakeDSLBase companion object
trait MakeDSLBase[T, AfterBind] extends AnyKindShim

Attributes

Companion:
object
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class MakeDSL[T]
class MakeNamedDSL[T]

Members list

Concise view

Type members

Inherited types

type LifecycleF[_] = Any

Attributes

Inherited from:
AnyKindShim

Value members

Concrete methods

final def from[I <: T : AnyConstructor]: AfterBind
final def from[I <: T : Tag](function: => I): AfterBind
final def from[I <: T](function: Functoid[I]): AfterBind

A function that receives its arguments from DI object graph, including named instances via izumi.distage.model.definition.Id annotation.

A function that receives its arguments from DI object graph, including named instances via izumi.distage.model.definition.Id annotation.

The following syntaxes are supported by extractor macro:

Inline lambda:

 make[Unit].from {
   i: Int @Id("special") => ()
 }

Method reference:

 def constructor(@Id("special") i: Int): Unit = ()

 make[Unit].from(constructor _)

 make[Unit].from(constructor(_))

Function value with an annotated signature:

 val constructor: (Int @Id("special"), String @Id("special")) => Unit = (_, _) => ()

 make[Unit].from(constructor)

Using intermediate vals will lose annotations when converting a method into a function value, Prefer passing inline lambdas such as { x => y } or method references such as (method _) or (method(_)).:

 def constructorMethod(@Id("special") i: Int): Unit = ()

 val constructor = constructorMethod _

 make[Unit].from(constructor) // SURPRISE: Will summon regular Int, not a "special" Int from DI object graph
 make[Unit].from(constructorMethod _) // Will work correctly: summon "special" Int

Prefer annotating parameter types, not parameters: class X(i: Int @Id("special")) { ... }

 case class X(i: Int @Id("special"))

 make[X].from(X.apply _) // summons special Int

Functoid forms an applicative functor via its izumi.distage.model.providers.Functoid.pure & izumi.distage.model.providers.Functoid#map2 methods

Attributes

See also:

izumi.distage.model.reflection.macros.FunctoidMacro]

Functoid is based on the Magnet Pattern: http://spray.io/blog/2012-12-13-the-magnet-pattern/

Essentially Functoid is a function-like entity with additional properties, so it's funny name is reasonable enough: https://en.wiktionary.org/wiki/-oid#English

final def fromEffect[F[_] : Tag, I <: T : Tag](instance: F[I]): AfterBind

Bind to a result of executing a purely-functional effect

Bind to a result of executing a purely-functional effect

Example:

 import cats.effect.concurrent.Ref
 import cats.effect.IO

 make[Ref[IO, Int]].named("globalMutableCounter").fromEffect(Ref[IO](0))

Attributes

final def fromEffect[F[_] : Tag, I <: T : Tag](function: Functoid[F[I]]): AfterBind
final def fromFactory[I <: T : FactoryConstructor]: AfterBind
def fromHas[R : HasConstructor, E : Tag, I <: T : Tag](effect: ZIO[R, E, I]): AfterBind
Implicitly added by MakeFromZIOHas
def fromHas[R : HasConstructor, E : Tag, I <: T : Tag](function: Functoid[ZIO[R, E, I]]): AfterBind
Implicitly added by MakeFromZIOHas
def fromHas[R : HasConstructor, E : Tag, I <: T : Tag](resource: ZManaged[R, E, I]): AfterBind
Implicitly added by MakeFromZIOHas
def fromHas[R : HasConstructor, E : Tag, I <: T : Tag](function: Functoid[ZManaged[R, E, I]])(implicit evidence$62: HasConstructor[R], evidence$63: Tag[E], evidence$64: Tag[I], d1: DummyImplicit): AfterBind
Implicitly added by MakeFromZIOHas
def fromHas[R : HasConstructor, E : Tag, I <: T : Tag](layer: ZLayer[R, E, Has[I]]): AfterBind
Implicitly added by MakeFromZIOHas
def fromHas[R : HasConstructor, E : Tag, I <: T : Tag](function: Functoid[ZLayer[R, E, Has[I]]])(implicit evidence$68: HasConstructor[R], evidence$69: Tag[E], evidence$70: Tag[I], d1: DummyImplicit, d2: DummyImplicit): AfterBind
Implicitly added by MakeFromZIOHas
def fromHas[R1 <: Lifecycle[LifecycleF, T] : AnyConstructor](implicit evidence$71: AnyConstructor[R1], tag: TrifunctorHasLifecycleTag[R1, T]): AfterBind
Implicitly added by MakeFromZIOHas

Adds a dependency on Local3[F]

Adds a dependency on Local3[F]

Warning: removes the precise subtype of Lifecycle because of Lifecycle.map: Integration checks mixed-in as a trait onto a Lifecycle value result here will be lost

Attributes

final def fromResource[R <: Lifecycle[LifecycleF, T] : AnyConstructor](implicit evidence$26: AnyConstructor[R], tag: LifecycleTag[R]): AfterBind

Bind to result of acquiring a resource

Bind to result of acquiring a resource

The resource will be released when the izumi.distage.model.Locator holding it is released. Typically, after .use is called on the result of izumi.distage.model.Injector#produce

You can create resources with Lifecycle.make, by inheriting from Lifecycle or by converting an existing cats.effect.Resource

You can bind a cats.effect.Resource directly:

 import cats.effect._

 val myResource: Resource[IO, Unit] = Resource.make(IO(println("Acquiring!")))(IO(println("Releasing!")))

 make[Unit].fromResource(myResource)

Attributes

See also:
final def fromResource[R](instance: R & Lifecycle[LifecycleF, T])(implicit tag: LifecycleTag[R]): AfterBind
final def fromResource[R](function: Functoid[R & Lifecycle[LifecycleF, T]])(implicit tag: LifecycleTag[R]): AfterBind
final def fromResource[R0, R <: Lifecycle[LifecycleF, T]](function: Functoid[R0])(implicit adapt: Aux[R0, R], tag: LifecycleTag[R]): AfterBind
final def fromValue[I <: T : Tag](instance: I): AfterBind
final def refEffect[F[_] : Tag, I <: T : Tag]: AfterBind

Bind to result of executing an effect bound to a key at F[I]

Bind to result of executing an effect bound to a key at F[I]

This will execute the effect again for every refEffect binding

Example:

 import cats.effect.concurrent.Ref
 import cats.effect.IO

 make[IO[Ref[IO, Int]]].named("counterFactory").from(Ref[IO](0))

 // execute the effect bound above to key `DIKey.get[IO[Ref[IO, Int]]].named("counterFactory")` to create and bind a new Ref
 make[Ref[IO, Int]].named("globalCounter1")
   .refEffect[IO, Ref[IO, Int]]("counterFactory")

 make[Ref[IO, Int]].named("globalCounter2")
   .refEffect[IO, Ref[IO, Int]]("counterFactory")

 // globalCounter1 and globalCounter2 are two independent mutable references

Attributes

final def refEffect[F[_] : Tag, I <: T : Tag](name: Identifier): AfterBind
final def refEffect[F[_] : Tag, I <: T : Tag, EFF : Tag]: AfterBind
final def refEffect[F[_] : Tag, I <: T : Tag, EFF : Tag](name: Identifier): AfterBind
final def refResource[R <: Lifecycle[LifecycleF, T]](implicit tag: LifecycleTag[R]): AfterBind

Bind to a result of acquiring a resource bound to a key at R

Bind to a result of acquiring a resource bound to a key at R

This will acquire a NEW resource again for every refResource binding

Attributes

final def refResource[R <: Lifecycle[LifecycleF, T]](name: Identifier)(implicit tag: LifecycleTag[R]): AfterBind
def todo(implicit pos: CodePositionMaterializer): AfterBind

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

final def using[I <: T : Tag]: AfterBind

Bind by reference to another bound key

Bind by reference to another bound key

Example:

 trait T
 class T1 extends T

 make[T1]
 make[T].using[T1]

Here, only T1 will be created. A class that depends on T will receive an instance of T1

Attributes

final def using[I <: T : Tag](name: Identifier): AfterBind

Inherited methods

final def fromHas[F[_, _, _] : Tag, R : HasConstructor, E : Tag, I <: T : Tag](function: Functoid[Lifecycle[[_] =>> F[R, E, _$40], I]])(implicit evidence$84: Tag[F], evidence$85: HasConstructor[R], evidence$86: Tag[E], evidence$87: Tag[I], d1: DummyImplicit): AfterBind
Implicitly added by MakeFromZIOHas

Adds a dependency on Local3[F]

Adds a dependency on Local3[F]

Warning: removes the precise subtype of Lifecycle because of Lifecycle.map: Integration checks mixed-in as a trait onto a Lifecycle value result here will be lost

Attributes

Inherited from:
MakeFromHasLowPriorityOverloads
final def fromHas[F[_, _, _] : Tag, R : HasConstructor, E : Tag, I <: T : Tag](resource: Lifecycle[[_] =>> F[R, E, _$35], I]): AfterBind
Implicitly added by MakeFromZIOHas

Adds a dependency on Local3[F]

Adds a dependency on Local3[F]

Warning: removes the precise subtype of Lifecycle because of Lifecycle.map: Integration checks mixed-in as a trait onto a Lifecycle value result here will be lost

Attributes

Inherited from:
MakeFromHasLowPriorityOverloads
final def fromHas[F[_, _, _] : Tag, R : HasConstructor, E : Tag, I <: T : Tag](function: Functoid[F[R, E, I]]): AfterBind
Implicitly added by MakeFromZIOHas

Adds a dependency on Local3[F]

Adds a dependency on Local3[F]

Attributes

Inherited from:
MakeFromHasLowPriorityOverloads
final def fromHas[F[_, _, _] : Tag, R : HasConstructor, E : Tag, I <: T : Tag](effect: F[R, E, I]): AfterBind
Implicitly added by MakeFromZIOHas

Adds a dependency on Local3[F]

Adds a dependency on Local3[F]

Attributes

Inherited from:
MakeFromHasLowPriorityOverloads