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);
})