get<T> static method

T? get<T>({
  1. dynamic key,
  2. dynamic args,
  3. bool withInjector = true,
})

Retrieves an object of type T from the ControlFactory.

This is the primary method for accessing your application's dependencies.

  • key: An optional key to distinguish between multiple objects of the same type. If not provided, the type T is used as the key.
  • args: Optional arguments to pass to the object's init method if it is being created for the first time. This is only applicable for objects that implement Initializable.
  • withInjector: This parameter is currently unused and will be removed in a future version.

If the requested object is not already in the factory's store, get will attempt to create it using a registered InitFactory. If the created object is a LazyControl, it will be stored for future retrievals.

Example:

// Retrieve a service by its type.
final myService = Control.get<MyService>();

// Retrieve an object by a custom key.
final specialConfig = Control.get<Config>(key: 'special_config');

Returns the requested object, or null if it cannot be found or created.

Implementation

static T? get<T>({dynamic key, dynamic args, bool withInjector = true}) =>
    factory.get<T>(key: key, args: args, withInjector: withInjector);