field-injection

Automates Rust struct dependency injection via #[injectable] and Container builder.

Updated May 10, 2026
One-click install
npx skills add https://github.com/jymchng/injectable --skill field-injection
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: field-injection
Source: https://github.com/jymchng/injectable/tree/main/skills/field-injection
Command: npx skills add https://github.com/jymchng/injectable --skill field-injection

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill addresses the challenge of manually wiring dependencies into Rust structs, providing a structured approach to dependency injection that simplifies the process and reduces errors.

Core Features & Use Cases

  • Automatic Dependency Injection: Automatically inject dependencies into struct fields with #[injectable] attribute.
  • Arc Support: Allows the use of Arc<T> fields with explicit annotation, enabling shared ownership.
  • Constructor Injection: Offers a way to handle non-injectable fields using constructor functions.
  • Use Case: When developing a Rust application with complex dependencies, this Skill can automatically wire up services like databases and caches, reducing boilerplate code and potential errors.

Quick Start

Add the #[injectable] attribute to your struct fields and use the Container::builder().build().await? to resolve dependencies.

Frequently Asked Questions about field-injection

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I automate struct dependency injection in Rust?

To automate struct dependency injection in Rust, add the #[injectable] attribute to struct fields and resolve them using Container::builder().build().await. This automatically wires up complex interdependent services like databases and caches, reducing manual boilerplate.

What is the best way to manage shared ownership during Rust dependency injection?

The best way to manage shared ownership during Rust dependency injection is using Arc<T> fields. You can explicitly annotate struct fields with Arc<T> to enable shared ownership when the framework automatically wires up your services and resolves dependencies.

How do I handle non-injectable fields when using an injection framework in Rust?

Handle non-injectable fields in a Rust injection framework by using constructor injection. This approach provides specific constructor functions to manually initialize fields that cannot be automatically resolved, while the rest of the struct uses the #[injectable] attribute.

Can I use this Rust automatic wiring approach for complex applications with multiple interdependent services?

Yes, you can use this Rust automatic wiring approach for complex applications with multiple interdependent services. It provides a structured approach to dependency resolution, automatically wiring up services like databases and caches to reduce boilerplate code and potential errors.

When should I use explicit constructor injection instead of automatic injection in Rust?

Use explicit constructor injection instead of automatic injection in Rust when dealing with non-injectable fields. While the #[injectable] attribute handles automatic wiring, constructor functions are required for fields that need custom initialization logic outside the automatic framework.