cubepod_core

Dependency injection and the core container for CubePod. Everything else in the framework depends on this.

What's inside

  • CubePod — the global DI container with O(1) lookups
  • Scope — singleton, factory, and scoped lifecycles
  • ResourcePool — a reusable pool of expensive objects (e.g. DB connections)
  • CubeObserver — hook into state/DI events for logging or analytics

Install

dependencies:
  cubepod_core: ^0.1.4

Usage

import 'package:cubepod_core/cubepod_core.dart';

// Register
CubePod.register<AuthService>(() => AuthService(), scope: Scope.singleton);
CubePod.register<UserRepo>(() => UserRepo(CubePod.get<AuthService>()));

// Resolve
final repo = CubePod.get<UserRepo>();

// Scoped lifetime (e.g. push on route open, pop on route close)
CubePod.pushScope();
CubePod.register<CartService>(() => CartService(), scope: Scope.scoped);
CubePod.popScope(); // CartService is disposed here automatically

See cubepod for the full docs.

Libraries

cubepod_core