singleton<T> abstract method

void singleton<T>(
  1. dynamic factory(
    1. ContainerInterface
    )
)

Registers a singleton factory for type T.

The factory is called once, and the instance is reused for all subsequent resolutions. This is equivalent to calling bind with singleton set to true.

  • factory: A function that takes the container and returns an instance of T.

Throws an exception if a binding for T already exists.

Implementation

void singleton<T>(dynamic Function(ContainerInterface) factory);