Bloc Registry
A centralised, type-safe registry for StateEmitter instances (both Bloc and Cubit).
BlocRegistry is the service locator that backs BlocProvider. You rarely interact with it directly; instead, wrap your composables with BlocProvider and resolve blocs where you need them.
Overview
// Registration — done automatically by BlocProvider
BlocProvider(listOf(CounterBloc(), AuthBloc())) {
AppContent()
}
// Resolution — anywhere in the composable tree
val counterBloc = BlocRegistry.resolve(CounterBloc::class)Error handling
resolve throws an IllegalStateException with a descriptive message if the requested type was not registered. This fail-fast behaviour catches configuration mistakes at development time.
Thread safety
All operations are expected to run on the main thread, consistent with the rest of the Bloc library.
Functions
Registers a list of StateEmitter instances, replacing any previous registrations.
Convenience overload accepting varargs.
Calls AnyHydratedBloc.resetToInitialState on every registered HydratedBloc, then wipes the entire HydratedBloc.storage.
Resolves a StateEmitter by its concrete KClass.