Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func From ¶
func From[T any](c *Container, ct Constructor[T]) T
From returns an instance of a constructor's value from the container. The constructor's New method is called the first time and the return value is cached. Future calls will return the cached value.
func From2 ¶
func From2[T, U any](c *Container, ct Constructor2[T, U]) (T, U)
From2 returns an instance of a constructor's value from the container. The constructor's New method is called the first time and the return values are cached. Future calls will return the cached values.
func Mock ¶ added in v0.2.0
func Mock[T any](c *Container, ct Constructor[T], v T)
Mock modifies the container cache to return a mocked instance for the constructor.
func Mock2 ¶ added in v0.2.0
func Mock2[T, U any](c *Container, ct Constructor2[T, U], v1 T, v2 U)
Mock2 modifies the container cache to return a mocked instance for the constructor.
Types ¶
type Constructor ¶
Constructor is implemented by any type that has a New method that accepts a container and returns a value, and a convenience From method that accepts a container and returns the value from the container.
Use Using to create a new Constructor.
func Using ¶
func Using[T any](fn func(*Container) T) Constructor[T]
Using creates a new Constructor from a function that accepts a container and returns a value.
type Constructor2 ¶
Constructor2 is implemented by any type that has a New method that accepts a container and returns two values, and a convenience From method that accepts a container and returns the values from the container.
Use Using2 to create a new Constructor2.
func Using2 ¶
func Using2[T, U any](fn func(*Container) (T, U)) Constructor2[T, U]
Using2 creates a new Constructor2 from a function that accepts a container and returns two values.
Use Using2 when a constructor returns multiple values for example an instance and an error.