[−][src]Crate kamikaze_di
Kamikaze DI
Dependency Injection framework.
Have a look at the readme file in the git repo for a more in depth discussion.
In use
ⓘThis example is not tested
extern crate kamikaze_di; #[macro_use] extern crate kamikaze_di_derive; use kamikaze_di::{Injector, ContainerBuilder, Result}; use std::rc::Rc; #[derive(Inject, Clone)] struct Config { pub db: String, } #[derive(InjectAsRc, Clone)] struct DatabaseConnection { config: Config, } #[derive(Inject, Clone)] struct UserRepository { db_connection: Rc<DatabaseConnection>, } let mut builder = ContainerBuilder::new(); builder .register::<Config>(Config { db: "localhost".to_string(), })?; let container = builder.build(); let user_repo_result: Result<UserRepository> = container.inject(); assert!(user_repo_result.is_ok()); let _user_repo = user_repo_result?;
Structs
Container | Dependency container. Can be used with Resolver or Injector. |
ContainerBuilder | Dependency container builder. |
Error | Error type. |
Traits
Inject | Resolves itself from a container. |
InjectAsRc | Resolves itself from a container as a Rc |
Injector | Resolves dependencies automatically. |
Resolver | Resolves dependencies. |
Type Definitions
Result | Result type |