pub package package publisher

Extensions for Dart

Microsoft.Extensions-style hosting, dependency injection, logging, configuration, and HTTP client plumbing for Dart and Flutter.

Highlights

  • hosting: Host builder with graceful startup/shutdown, background services, cancellation tokens, and lifetime notifications.
  • dependency_injection: Familiar ServiceCollection APIs with singleton/scoped/transient lifetimes and validation options.
  • configuration: Compose JSON, environment variables, command line, INI, XML, in-memory, and stream-based sources with reload support.
  • logging: Structured logging abstractions with console/debug/json/systemd formatters, filter rules, and scopes.
  • options: Typed options with validation, change tokens, and monitors.
  • http: IHttpClientFactory-style pipeline with delegating handlers, logging, handler lifetime control, and header redaction.
  • File providers, globbing, caching, and primitives that mirror the .NET ecosystem.

Install

dart pub add extensions

Quick start: minimal host with logging

import 'package:extensions/hosting.dart';

final _builder = Host.createApplicationBuilder()
  ..addLogging((logging) => logging.addSimpleConsole());

final host = _builder.build();

Future<void> main() async => await host.run();

More examples

See packages/extensions/example for focused samples (background services, configuration, console formatters, caching, HTTP client logging, and more).

  • extensions_flutter – bootstraps Flutter with the same host/DI/logging stack.

Credits

This is a Dart port of the Microsoft.Extensions.* stack from the dotnet/runtime repository, adapted where Dart and C# differ.

Libraries

caching
Contains classes and abstractions for caching data in memory and distributed systems.
configuration
Contains classes for reading application configuration from various sources.
dependency_injection
Provides a dependency injection container for managing services and their lifetimes.
diagnostics
Provides metrics and instrumentation support for application telemetry.
file_providers
Provides abstractions for file system operations with change tracking and composite file providers.
file_system_globbing
Provides support for matching file system paths using glob patterns with include/exclude semantics.
hosting
Provides classes for managing application lifetime, hosting background services, and coordinating application startup/shutdown.
http
Provides typed HTTP client factory with lifetime management and request/response logging.
logging
Provides a flexible logging infrastructure with support for multiple log providers and structured logging.
options
Provides types for implementing the options pattern for strongly-typed configuration.
primitives
Contains fundamental primitives and change notification types used throughout the extensions package.
system
Provides fundamental system types for resource management, threading, and common exceptions.