BLoC and Dependency Injection in Holigo: What We Gained and What It Costs - Part 3
Architecture & Decision Log·October 16, 2026·10 min read
All notes

BLoC and Dependency Injection in Holigo: What We Gained and What It Costs - Part 3

From GetX to BLoC and get_it: how we structured deterministic state streams, organized modular feature injectors, and consciously balanced the engineering trade-offs.

Two Intertwined Decisions That Dictate Team Scalability#

In Part 2 of this series, we unpacked how every feature module in Holigo was restructured into three decoupled layers: Presentation, Domain, and Data. But establishing layer boundaries is only half the battle. For those layers to communicate without descending back into chaotic coupling, an engineering team must answer two interdependent architectural questions:

How do screens communicate state mutations predictably across asynchronous lifecycles? And how do layers receive the concrete services they depend on without hardcoding implementations inside UI widgets?

For Holigo, we paired the BLoC (Business Logic Component) pattern with get_it as our dependency injection service locator. While developer forums often treat state management and dependency injection as isolated debates, in production they directly influence each other. BLoCs consume Domain Use Cases, Use Cases require Repository interfaces, and Repositories depend on low-level Data Sources. If your dependency graph is brittle, your state management will inevitably crack under pressure.

Here is an honest breakdown of why we chose this combination, how we structured it across dozens of modules, and the operational price we consciously chose to pay.

FIG.
BLoC Data Flow: From UI Interaction to Immutable State
Unidirectional Data Flow
01

UI Dispatches Event

Presentation Layer

Screen widget dispatches an explicit Event to BLoC without executing any business logic directly.

02

Event Handler & Logic

BLoC Controller

BLoC intercepts the event, emits a Loading state, and delegates work to the Domain Use Case.

03

Use Case Execution

Domain Layer

Use Case validates business rules and fetches models via pure abstract repository contracts.

04

Emit Immutable State

State Emission

BLoC streams out an immutable State (Success/Failure) causing reactive UI rebuilding.

Core Lesson:

Unidirectional data flow ensures every UI change leaves a clear, deterministic trail of events and states, making debugging and unit testing straightforward.

From GetX to BLoC: Restoring Deterministic State Streams#

Our primary catalyst for abandoning GetX was the urgent need for predictable, auditable state mutations. In a multi-service transactional application handling continuous monetary top-ups and travel bookings, "magic reactivity" was a liability. When state changes can be triggered implicitly from anywhere inside a controller or UI callback, tracking down the root cause of an anomalous screen render turns into an exhausting guessing game.

BLoC fundamentally eliminated that unpredictability through strict unidirectional data flow:

The Presentation layer is strictly forbidden from mutating state directly. Instead, UI widgets dispatch explicit Events (such as SearchShipSchedule or SelectBerthQuota). The BLoC catches the event, sets an immutable status flag, delegates execution to one or more Domain Use Cases, and emits an immutable State containing both the payload and a distinct request lifecycle enum (initial, loading, success, failure).

Because states are strictly immutable and emitted over standard Dart streams, every visual change on screen leaves an audit trail. When a customer support ticket arrives questioning why a booking screen displayed an error banner, engineers don't have to guess: they can reproduce the exact event sequence and inspect the corresponding emitted states deterministically.

Modular Dependency Injection with get_it#

Once a feature is split into three decoupled layers, a single screen depends on a cascade of abstractions: ShipScreen needs ShipBloc, which requires GetShipSchedulesUseCase, which depends on ShipRepository, which requires ShipRemoteDataSource, ShipLocalDataSource, and the centralized DioClient.

If these dependencies were assembled manually inside screen constructors, the presentation layer would quickly drown in boilerplate wiring. Conversely, if all dependencies were dumped into one gigantic monolithic initialization file, git merge conflicts would paralyze team velocity whenever multiple developers ship features simultaneously.

To solve this, we combined get_it with a Modular Feature Injector pattern:

  1. Central Service Locator: A core setupLocator() routine runs during application bootstrap to register shared singletons: the centralized Dio HTTP client, secure token storage, database engines, and router bridges.
  2. Feature-Level Injectors: Each domain module (e.g., features/ship/di/ship_injector.dart) owns an isolated manifest responsible for registering its local data sources, repository implementations, pure domain use cases, and BLoC factories.
  3. Decoupled Registration: The central locator simply invokes each feature injector sequentially during startup, ensuring features remain fully self-contained packages.
FIG.
Dependency Injection Graph: Central Locator & Feature Injectors
Service Locator Architecture
App Root Service Locator (get_it / setupLocator)Centralized & Modular

The central setupLocator() registers shared core instances and delegates to individual feature injector manifests at app startup.

Core Network Dio
Shared Preferences
Secure Storage
Ship Feature Injector
Core Infrastructure
Global Singletons
  • •Dio Client Wrapper: Centralized HTTP client with token and error interceptors.
  • •Storage Services: Encrypted vault and fast key-value preferences cache.
  • •App Router: Declarative go_router instance with auth gatekeeper.
Registered as lazy singletons across app lifecycle
Feature Modules
Factory & Scoped
  • •Data Sources & Repo: Remote & local sources bound to repository implementations.
  • •Domain Use Cases: Isolated pure Dart use cases registered per feature.
  • •BLoC Providers: Factory registrations ensuring fresh state per screen flow.
Abstract contracts simplify automated test mocks
Core Lesson:

Decomposing DI registration into per-feature injectors keeps the bootstrap locator concise, modular, and maintainable across teams.

This structure simplified testing right away. UI widgets request their BLoC from the injector without knowing how its internal dependency graph was constructed. Furthermore, because repositories and data sources are registered against abstract interfaces, swapping in mock implementations during automated unit testing takes minimal setup.

State Scoping: Global App Root BLoCs vs Scoped Screen BLoCs#

One of the most consequential design decisions in BLoC architecture is deciding where a BLoC should live in the widget hierarchy. In Holigo, we categorized state into two distinct lifecycles:

Global BLoCs at the App Root: A select group of long-lived BLoCs are registered at the application root to make shared system context universally available across all screens. These govern app-wide concerns: dynamic theme settings, active localization, persistent user profile sessions, push notification badges, and the Ship master harbour dataset. Because these datasets are accessed by multiple tabs and modal dialogs, hosting them globally avoids repetitive disk reads and cumbersome parameter passing across routes.

Scoped BLoCs per Screen Flow: In contrast, transactional workflows (such as passenger seat selection, payment verification, and flight schedule search) are scoped strictly to the lifecycle of their respective screens. They are spawned when the screen mounts and automatically disposed from memory when the user navigates away.

FIG.
State Scoping: Global BLoCs vs Per-Screen BLoCs
Lifecycle Management
Global BLoCs at App RootApp Lifecycle Scope
  1. 01Purpose: Application-wide state such as Theme, Locale, User Session, and System Notifications.
  2. 02Pros: Instantly accessible anywhere in the widget tree without parameter drilling.
  3. 03Trade-off: Persists in memory permanently; overusing it leads to bloated app-wide coupling.
Strictly limited to persistent global concerns
Per-Screen Scoped BLoCsRoute Lifecycle Scope
  1. 01Purpose: Feature-specific transactional flows like Ship Search, Ticket Checkout, or Passenger Input.
  2. 02Pros: Automatically disposed when navigating away; zero memory footprint leakage.
  3. 03Trade-off: Screen data resets on exit unless explicitly persisted to cache storage.
Recommended default for transactional feature modules
Core Lesson:

Only state genuinely required across distinct application domains belongs at the app root; everything else must stay strictly scoped to its screen.

This separation keeps memory consumption lean and guarantees that stale transactional form inputs are never accidentally carried over into a customer's subsequent booking session.

The Real-World Price: Boilerplate, Runtime Registration, and Discipline#

No architectural choice is without consequence. While BLoC and get_it delivered rock-solid stability, they introduced tangible overhead that our engineering team had to manage proactively:

  • Proliferation of Files and Boilerplate: Adding even a simple toggle button now requires editing event definitions, state classes, bloc handlers, use case contracts, and injector files. For rapid prototypes, this ceremony feels tedious.
  • Runtime Dependency Failures: Unlike compile-time dependency injection frameworks, forgetting to register a dependency in get_it only surfaces when the app attempts to resolve the instance at runtime. To mitigate this risk, we established automated smoke tests and strict pull-request checklists to verify that all feature injectors are wired before merging.
  • Root Coupling Gravity: Global BLoCs create a subtle gravitational pull: developers are frequently tempted to promote screen-specific state to the app root simply because it is convenient to access. Without continuous architectural governance, the global state layer can quickly devolve into a bloated, coupled bottleneck.
  • Testability as a Prerequisite, Not an Automatic Outcome: Decoupling architecture makes code testable, but it does not write tests for you. Establishing the pattern is merely the foundation; building consistent unit and stream test coverage across all BLoCs remains continuous engineering homework.

What You Can Take from This Story#

If you are evaluating state management and dependency injection for your own mobile codebase, here are four practical principles to keep in mind:

  • Pick State Management for Predictability, Not Popularity: We chose BLoC because deterministic streams and auditable state transitions were essential for financial transactions, not because of industry hype.
  • Decompose Your DI Graph by Feature: Never dump all service registrations into a single file. Modular feature injectors ensure new team members can build, test, and maintain their domain without creating merge conflicts.
  • Enforce Strict Scoping Boundaries: Keep the application root reserved exclusively for truly global, long-lived state. Treat per-screen scoped BLoCs as the default for all transactional and UI-heavy flows.
  • Build Guardrails for Runtime Resolution: If using service locators like get_it, implement startup sanity checks or automated DI test suites to catch unregistered dependencies long before your code reaches production.

Closing#

State management and dependency injection are the central nervous system of any Flutter application. By committing to BLoC's explicit event-state flow and structuring get_it into modular feature injectors, Holigo achieved the predictability and stability required to scale an enterprise codebase across multiple teams.

In Part 4 of this series, we will examine our navigation architecture and app startup sequence: how go_router and a dedicated authentication middleware keep the application's entry point clean, secure, and resilient.

Thanks for reading :)

P.S. This series is written at the level of software design decisions and mobile system architecture, without disclosing proprietary code or internal company data. If you have questions about BLoC state flows, DI patterns, or want to share your own team's migration experience, let's connect and discuss!