Serinus providers and di

From francescovallone/serinus · View interactive version

Serinus providers and di is an AI agent skill from the GitHub repository francescovallone/serinus. Use when defining Serinus providers, dependency injection, module exports, lifecycle hooks, or custom provider registrations such as Provider.composed, Provider.forClass, and Provider.forValue.

How to use this skill

Skill file

Serinus Providers and DI

Guidelines

Prefer This Pattern

import 'package:serinus/serinus.dart';

class UsersService extends Provider {
  UsersService(this.apiBaseUrl);

  final String apiBaseUrl;
}

class UsersModule extends Module {
  UsersModule()
      : super(
          providers: [
            Provider.forValue<String>('https://api.example.com', name: 'API_URL'),
            Provider.composed<UsersService>(
              (context) async => UsersService(context.use<String>('API_URL')),
              inject: [ValueToken.of<String>('API_URL')],
            ),
          ],
          exports: [UsersService, Export.value<String>('API_URL')],
        );
}

Class Provider Pattern

final paymentProvider = Provider.forClass<PaymentService>(
  useClass: StripePaymentService(),
);

Use this when a module should inject PaymentService while the concrete implementation stays replaceable.

Lifecycle Pattern

class CacheProvider extends Provider with OnApplicationInit, OnApplicationShutdown {
  @override
  Future<void> onApplicationInit() async {}

  @override
  Future<void> onApplicationShutdown() async {}
}

Avoid

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.