#dependency-injection #framework #macro #ioc

macro shellder-macros

A lightweight, type-safe dependency injection and application framework for Rust inspired by Spring

2 releases

0.1.5 Jul 27, 2025
0.1.0 Jul 5, 2025

#51 in #ioc


Used in shellder

Apache-2.0

11KB
172 lines

๐Ÿš Shellder

A lightweight, Spring-inspired Dependency Injection framework for Rust. "A Crab needs its Shell"


โœจ Overview

Shellder brings a modular, ergonomic approach to Rust applications by offering:

  • ๐Ÿ“ฆ Dependency Injection via #[component] and #[derive(App)] macros
  • โš™๏ธ Lifecycle Hooks (startup, run, cleanup)
  • ๐Ÿ› ๏ธ Compile-time struct injection
  • ๐Ÿงต Thread-safe container (Arc-based)
  • ๐Ÿ”ง Optional lightweight logger

Built for CLI tools, long-running services, or application backends.


๐Ÿš€ Quick Start

Add Shellder to your project

[dependencies]
shellder = "0.2.5"

Example

use std::sync::Arc;
use shellder::{App, Container, Hooks, Lifecycle};

pub struct Logger;
impl Logger {
    pub fn log(&self, msg: &str) {
        println!("[LOG] {}", msg);
    }
}

#[derive(App)]
pub struct HelloApp {
    #[component]
    logger: Arc<Logger>,
}

impl Hooks for HelloApp {
    fn startup(&self) {
        self.logger.log("Starting up!");
    }

    fn run(&self) {
        self.logger.log("Running...");
    }

    fn cleanup(&self) {
        self.logger.log("Shutting down.");
    }
}

Running this app will automatically inject dependencies and call hooks in order.


๐Ÿงฉ Features in v0.2.5

โœ… #[component] macro for auto-registration โœ… #[derive(App)] macro to auto-generate main() โœ… Lifecycle Hooks trait support โœ… Thread-safe singleton container โœ… Optional custom logger โœ… Works without tokio or async runtime


๐Ÿ› ๏ธ Planned Roadmap

  • ๐Ÿ”– Named registration & resolution ("db", "logger")
  • ๐Ÿงช Test container for mocking dependencies
  • ๐Ÿงฌ Config loader (from .toml or .yaml)
  • ๐Ÿงฑ Fluent container builder
  • ๐Ÿงฉ Macro plugins: #[value], #[config], etc.
  • ๐Ÿงต Async hook support
  • ๐Ÿ“ Workspace support & automatic example runner

๐Ÿ’ก Philosophy

Shellder follows a Rust-first vision:

  • โœ… Strong compile-time guarantees
  • ๐Ÿงผ Minimal runtime dependencies
  • ๐Ÿ› ๏ธ Clean syntax with macros
  • ๐Ÿค Integrates well with your architecture

๐Ÿ“ License

Licensed under Apache-2.0.


๐Ÿค Contributing

Bug reports, PRs, and feedback are welcome! Open an issue to discuss enhancements or integrations.


๐Ÿ“ฃ Stay Tuned

Shellder is under active development. Watch the repo for updates on:

  • Configuration loading
  • DI graphs
  • CLI/web framework integrations
  • Logging plugins

Dependencies

~175โ€“590KB
~14K SLoC