Springtime Dependency Injection
A dependency injection crate inspired by the Spring Framework in Java.
The philosophy of Springtime is to provide the means of easy dependency
injection without unnecessary manual configuration, e.g. without the need to
explicitly create dependencies and storing them in containers. The core concept
is the Component - something that can be created, injected, and managed by the
framework. As much work as possible is placed on compile-time metadata creation
and automatic component discovery, thus allowing users to focus on the usage
of components, rather than their creation and management. With an accent
placed on attributes, dependency configuration becomes declarative (what I want
to accomplish) leaving the gritty details the framework itself (how to
accomplish what was requested).
Features
- Concrete and trait object injection
- Automatic and manual registration support
- Component filtering
- Conditional component registration
- Component priorities
- Custom constructor functions
- Per-field configurable initialization
- Customizable instance scopes
- Async + sync support (runtime agnostic)
Basic usage
Springtime is highly configurable, but the most basic usage example is quite simple and consists of using a few attributes to fully configure the dependency chain. For tutorial, advanced features, and patterns, please look at the examples, which form a step-by-step guide.
use ComponentFactoryBuilder;
use ;
use ;
// this is a trait we would like to use in our component
// this is a dependency which implements the above trait and also is an injectable component
;
// we're telling the framework to provide TestDependency when asked for dyn TestTrait
// this is another component, but with a dependency
// note: for the sake of simplicity, errors are unwrapped, rather than gracefully handled