Crates.io | rs-macro-di |
lib.rs | rs-macro-di |
version | 0.3.4 |
source | src |
created_at | 2024-06-11 10:41:28.599872 |
updated_at | 2024-06-15 08:55:31.534325 |
description | Rust dependency injection by macro |
homepage | https://github.com/Steeoghr/rs-macro-di |
repository | https://github.com/Steeoghr/rs-macro-di |
max_upload_size | |
id | 1268067 |
size | 17,660 |
rs-macro-di = "0.2.0"
or add with cargo:
cargo add rs-macro-di
// Add singleton service
add_singleton!(Arc::new(SingletonService::new()));
// Add scoped service
add_scoped!(ScopedService);
// Add transient service
add_transient!(ScopedService);
let service: Arc<ServiceClass> = provide!(ServiceClass);
// Get provider
let mut provider = provider!();
// or
let mut provider = get_mut_service_provider();
// Add singleton service
provider.add_singleton(Arc::new(SingletonService::new()));
// Add scoped service
provider.add_scoped::<ScopedService>();
// Add transient service
provider.add_transient::<ScopedService>();
// Get provider
let provider = provider!();
let service: Arc<ServiceClass> = provider.provide::<ServiceClass>();
// Add scoped service
add_scoped!(ScopedService);
// scoped service instances are cleared at the end of with_scope
with_scope(|| {
let service: Arc<ScopedService> = provide!(ScopedService);
})