ZuraffaDIContainer class
A lightweight dependency-injection container that wraps GetIt.
ZuraffaDIContainer provides a thin, typed facade over GetIt so that generated DI setup code and micro-frontend plugins can exchange service registrations through a stable contract that does not leak the full GetIt API surface.
Registration methods
| Method | Behaviour |
|---|---|
| registerLazySingleton | Resolves lazily on first get call; cached thereafter. |
| registerFactory | Creates a new instance on every get call. |
| registerSingleton | Creates and caches immediately at registration time. |
| registerInstance | Binds an already-created object (useful for |
| test mocks and manual wiring). |
Override behaviour
When override is true (default false), any existing registration
for type T is unregistered before the new one is registered. This
allows plugins to replace core bindings:
// Core registration
await di.registerLazySingleton<PaymentGateway>(() => StripeGateway());
// Plugin override
await di.registerLazySingleton<PaymentGateway>(
() => MockPaymentGateway(),
override: true,
);
When override is false and a binding already exists, registration
throws a StateError naming the conflicting type T.
Interceptor registration
The container also hosts an interceptorRegistry for UseCase interceptor chains. Use registerInterceptor to add interceptors.
Interoperability
Generated DI registration helpers accept a raw GetIt reference. Callers can pass getIt directly to bridge between this wrapper and generated code without unwrapping.
final di = ZuraffaDIContainer();
// Manual registration
await di.registerLazySingleton<MyService>(() => MyServiceImpl());
// Interop with generated code that expects GetIt
generatedRegisterAll(di.getIt);
final service = di.get<MyService>();
Constructors
- ZuraffaDIContainer({GetIt? getIt, InterceptorRegistry? interceptorRegistry})
-
Creates a new ZuraffaDIContainer wrapping
getIt.
Properties
- getIt → GetIt
-
The underlying GetIt instance that backs this container.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- interceptorRegistry → InterceptorRegistry
-
Registry for UseCase interceptor chains.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
get<
T extends Object> ({String? instanceName}) → T -
Retrieves the registered instance of type
T. -
isRegistered<
T extends Object> ({String? instanceName}) → bool -
Returns
trueif a registration forTexists. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
registerFactory<
T extends Object> (T factoryFunc(), {String? instanceName, bool override = false}) → Future< void> -
Registers a factory for type
T. -
registerInstance<
T extends Object> (T instance, {String? instanceName, bool override = false}) → Future< void> -
Binds an already-instantiated
instanceas a singleton for typeT. -
registerInterceptor<
In, Out> (InterceptorEntry< In, Out> entry) → void -
Registers an interceptor for UseCase input type
Inand output typeOut. -
registerLazySingleton<
T extends Object> (T factoryFunc(), {String? instanceName, bool override = false}) → Future< void> -
Registers a lazy singleton factory for type
T. -
registerSingleton<
T extends Object> (T factoryFunc(), {String? instanceName, bool override = false}) → Future< void> -
Registers an eager singleton for type
T. -
reset(
) → Future< void> - Resets the container, clearing all registrations and interceptors.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited