final case class ProviderMagnet[+A](get: Provider) extends Product with Serializable
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)
Annotation processing is done by a macro and macros are rarely perfect, Prefer passing an inline lambda such as { x => y } or a method reference such as (method _) or (method(_)) Annotation info may be lost ONLY in a few cases detailed below, though:
- If an annotated method has been hidden by an intermediate
val
- If an
.apply
method of a case class is passed when case class _parameters_ are annotated, not their types
As such, prefer annotating parameter types, not parameters: class X(i: Int @Id("special")) { ... }
When binding a case class to constructor, prefer passing new X(_)
instead of X.apply _
because apply
will
not preserve parameter annotations from case class definitions:
case class X(@Id("special") i: Int) make[X].from(X.apply _) // summons regular Int make[X].from(new X(_)) // summons special Int
HOWEVER, if you annotate the types of parameters instead of their names, apply
WILL work:
case class X(i: Int @Id("special")) make[X].from(X.apply _) // summons special Int
Using intermediate vals will lose annotations when converting a method into a function value,
prefer using annotated method directly as method reference (method _)
:
def constructorMethod(@Id("special") i: Int): Unit = () val constructor = constructorMethod _ make[Unit].from(constructor) // Will summon regular Int, not a "special" Int from DI object graph
ProviderMagnet forms an applicative functor via its ProviderMagnet.pure & map2 methods
- See also
'Magnet' in the name refers to the Magnet Pattern: http://spray.io/blog/2012-12-13-the-magnet-pattern/
- Alphabetic
- By Inheritance
- ProviderMagnet
- Serializable
- Product
- Equals
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def addDependencies(keys: Seq[DIKey]): ProviderMagnet[A]
- def addDependency(key: DIKey): ProviderMagnet[A]
- def addDependency[B](implicit arg0: Tag[B]): ProviderMagnet[A]
Add
B
as an unused dependency of this Provider - def ap[B, C](that: ProviderMagnet[B])(implicit ev: <:<[A, (B) => C], tag: Tag[C]): ProviderMagnet[C]
Apply a function produced by
this
Provider to the argument produced bythat
Provider - final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- def flatAp[B](that: ProviderMagnet[(A) => B])(implicit arg0: Tag[B]): ProviderMagnet[B]
Applicative's
ap
method - can be used to chain transformations likeflatMap
.Applicative's
ap
method - can be used to chain transformations likeflatMap
. Apply a function produced bythat
Provider to the argument produced bythis
Provider - val get: Provider
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def map[B](f: (A) => B)(implicit arg0: Tag[B]): ProviderMagnet[B]
- def map2[B, C](that: ProviderMagnet[B])(f: (A, B) => C)(implicit arg0: Tag[C]): ProviderMagnet[C]
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def productElementNames: Iterator[String]
- Definition Classes
- Product
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- def zip[B](that: ProviderMagnet[B]): ProviderMagnet[(A, B)]