di

Dependency Injection (DependenciesContainer + Scopes)

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "di" with this command: npx skills add yelmuratoff/agent_sync/yelmuratoff-agent-sync-di

Dependency Injection (DependenciesContainer + Scopes)

When to use

  • Adding a new repository, datasource, client, or service.

  • Wiring dependencies into a feature’s BLoC.

  • Creating a feature scope widget that provides BLoCs and exposes a small, stable UI API.

Steps

  1. Put long-lived dependencies into the container

Conceptually, these live in DependenciesContainer (repositories, clients, DAOs, shared utilities).

Access pattern:

final repo = context.repository.ordersRepository; final deps = context.dependencies;

Do not introduce GetIt or any other global service locator.

  1. Provide feature state via Scope widgets (not raw BlocProvider)

Instead of sprinkling BlocProvider in widgets, create a Scope widget that:

  • creates the BLoC(s)

  • injects dependencies from context.repository

  • exposes typed selectors and typed event dispatchers

Template:

import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart';

import 'package:your_app/src/common/presentation/scopes/bloc_scope.dart';

import '../bloc/orders_bloc.dart'; import '../bloc/orders_event.dart'; import '../bloc/orders_state.dart';

final class OrdersScope extends StatelessWidget { const OrdersScope({required this.child, super.key});

final Widget child;

static const BlocScope<OrdersEvent, OrdersState, OrdersBloc> _scope = BlocScope();

static ScopeData<bool> get isLoadingOf => _scope.select((state) => state is OrdersLoadingState);

static UnaryScopeMethod<void> get refresh => _scope.unary((context, _) => const OrdersRefreshEvent());

@override Widget build(BuildContext context) { return BlocProvider( create: (context) => OrdersBloc( repository: context.repository.ordersRepository, )..add(const OrdersStartedEvent()), child: child, ); } }

  1. Consume in UI via the scope API

final isLoading = OrdersScope.isLoadingOf(context); OrdersScope.refresh(context, null);

If the scope becomes too large, split by sub-feature scopes rather than exposing raw BLoCs.

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Automation

routing

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

bloc

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

effective-commenting

No summary provided by upstream source.

Repository SourceNeeds Review