diff options
Diffstat (limited to 'examples/factory')
-rw-r--r-- | examples/factory/bootstrap.rs | 18 | ||||
-rw-r--r-- | examples/factory/main.rs | 10 |
2 files changed, 16 insertions, 12 deletions
diff --git a/examples/factory/bootstrap.rs b/examples/factory/bootstrap.rs index b752764..ad8c4d3 100644 --- a/examples/factory/bootstrap.rs +++ b/examples/factory/bootstrap.rs @@ -1,3 +1,5 @@ +use std::error::Error; + use syrette::ptr::TransientPtr; use syrette::DIContainer; @@ -9,24 +11,22 @@ use crate::interfaces::user_manager::IUserManager; use crate::user::User; use crate::user_manager::UserManager; -pub fn bootstrap() -> DIContainer +pub fn bootstrap() -> Result<DIContainer, Box<dyn Error>> { let mut di_container: DIContainer = DIContainer::new(); di_container .bind::<dyn IUserManager>() - .to::<UserManager>() - .unwrap(); + .to::<UserManager>()?; - di_container - .bind::<IUserFactory>() - .to_factory(&|name, date_of_birth, password| { + di_container.bind::<IUserFactory>().to_factory( + &|name, date_of_birth, password| { let user: TransientPtr<dyn IUser> = TransientPtr::new(User::new(name, date_of_birth, password)); user - }) - .unwrap(); + }, + )?; - di_container + Ok(di_container) } diff --git a/examples/factory/main.rs b/examples/factory/main.rs index bf3d43b..0f1a97b 100644 --- a/examples/factory/main.rs +++ b/examples/factory/main.rs @@ -7,21 +7,25 @@ mod interfaces; mod user; mod user_manager; +use std::error::Error; + use bootstrap::bootstrap; use crate::interfaces::user_manager::IUserManager; -fn main() +fn main() -> Result<(), Box<dyn Error>> { println!("Hello, world!"); - let di_container = bootstrap(); + let di_container = bootstrap()?; - let mut user_manager = di_container.get::<dyn IUserManager>().unwrap(); + let mut user_manager = di_container.get::<dyn IUserManager>()?.transient()?; user_manager.fill_with_users(); println!("Printing user information"); user_manager.print_users(); + + Ok(()) } |