From c1e682c25c24be3174d44ceb95b0537c38299d0c Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 12 Sep 2022 20:22:13 +0200 Subject: feat!: allow factories access to DI container BREAKING CHANGE: Factory types should now be written with the Fn trait instead of the IFactory trait and the to_factory & to_default_factory methods of BindingBuilder now expect a function returning a factory function --- examples/factory/bootstrap.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'examples/factory/bootstrap.rs') diff --git a/examples/factory/bootstrap.rs b/examples/factory/bootstrap.rs index 19fad81..f8bef6e 100644 --- a/examples/factory/bootstrap.rs +++ b/examples/factory/bootstrap.rs @@ -4,11 +4,8 @@ use std::rc::Rc; use syrette::ptr::TransientPtr; use syrette::DIContainer; -// Interfaces use crate::interfaces::user::{IUser, IUserFactory}; use crate::interfaces::user_manager::IUserManager; -// -// Concrete implementations use crate::user::User; use crate::user_manager::UserManager; @@ -20,14 +17,14 @@ pub fn bootstrap() -> Result, Box> .bind::() .to::()?; - di_container.bind::().to_factory( - &|name, date_of_birth, password| { + di_container.bind::().to_factory(&|_| { + Box::new(move |name, date_of_birth, password| { let user: TransientPtr = TransientPtr::new(User::new(name, date_of_birth, password)); user - }, - )?; + }) + })?; Ok(di_container) } -- cgit v1.2.3-18-g5258