You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello there! I'm the shaku dev, and noticed this new DI library. It looks pretty interesting. I especially like the various levels of scope available.
I noticed that under "Can be used without dyn traits" you list shaku as "No". In fact, shaku can be used without using trait objects as dependencies. It does require a manual implementation of Component (or Provider), but see the following example:
use shaku::{module,Component,HasComponent,Interface,Module,ModuleBuildContext};use std::sync::Arc;traitService:Interface{}// Just a normal struct, no associated traitstructDependency;// A manual impl of Component is necessary because the derive automatically assumes// the interface is a trait. This restriction could be relaxed in a future release, such that// #[derive(Component)] + #[shaku(interface = Self)] works.impl<M:Module>Component<M>forDependency{typeInterface = Self;typeParameters = ();fnbuild(_:&mutModuleBuildContext<M>, _:Self::Parameters) -> Box<Self::Interface>{Box::new(Self)}}#[derive(Component)]#[shaku(interface = Service)]structServiceImpl{// Notice that there is no `dyn` here!#[shaku(inject)]dependency:Arc<Dependency>,}implServiceforServiceImpl{}module!{TestModule{
components = [Dependency, ServiceImpl],
providers = []}}fnmain(){let module = TestModule::builder().build();let service:&dynService = module.resolve_ref();}
The text was updated successfully, but these errors were encountered:
Hello there! I'm the shaku dev, and noticed this new DI library. It looks pretty interesting. I especially like the various levels of scope available.
I noticed that under "Can be used without dyn traits" you list shaku as "No". In fact, shaku can be used without using trait objects as dependencies. It does require a manual implementation of
Component
(orProvider
), but see the following example:The text was updated successfully, but these errors were encountered: