fibre_ioc

Crates.iofibre_ioc
lib.rsfibre_ioc
version0.5.2
created_at2025-06-16 05:57:17.844787+00
updated_at2025-06-16 16:10:41.315706+00
descriptionA flexible, thread-safe and dynamic Inversion of Control (IoC) container for Rust.
homepagehttps://github.com/excsn/fibre
repositoryhttps://github.com/excsn/fibre
max_upload_size
id1713920
size82,797
Norm O (normano)

documentation

README

Fibre IoC

Crates.io Docs.rs License

fibre_ioc is a flexible, thread-safe and dynamic Inversion of Control (IoC) container for Rust.

It provides a robust solution for managing dependencies within an application, promoting loose coupling and enhancing testability. Unlike containers that require a single, upfront initialization, Fibre IoC allows for dynamic registration of services at any point during the application's lifecycle, making it ideal for complex, modular systems.

Key Features

Thread-Safe by Design

The container is built from the ground up for concurrency. It uses high-performance concurrent data structures (dashmap and once_cell) to ensure that registering and resolving services is completely thread-safe, without sacrificing performance.

Multiple Service Lifetimes

Fibre IoC supports different service lifetimes to suit various use cases:

  • Singleton: A single instance is created on first use and shared for all subsequent requests.
  • Transient: A new instance is created every time the service is requested.
  • Instance: A pre-existing object is registered directly with the container.

Global & Local Containers

For convenience, a static global container is available via the global() function. For testing or modularity, you can create fully isolated Container instances with Container::new(), preventing any interference between dependency scopes.

Ergonomic and Type-Safe API

Resolve dependencies effortlessly with the resolve! macro, which provides a concise, panicking API for retrieving services. For cases where failure is expected, the container.get() method returns an Option, allowing for graceful error handling.

Robust Circular Dependency Detection

Fibre IoC automatically detects and prevents circular dependencies during resolution. If Service A depends on B, and B depends on A, the container will panic with a clear error message instead of causing a stack overflow.

Installation

Add Fibre IoC to your project by running:

cargo add fibre_ioc

Getting Started

For a detailed guide on core concepts and advanced usage patterns, please see the Usage Guide.

The tests/ directory in the repository also contains a comprehensive suite of examples demonstrating every feature, from basic registration to complex concurrent scenarios.

For a complete API reference, see the documentation on docs.rs.

License

This library is distributed under the terms of the MPL-2.0 license.

Commit count: 63

cargo fmt