From e8e48906a3899e71c9c9d86a3d4528cb7d17e5b9 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 17 Sep 2022 12:57:18 +0200 Subject: refactor!: make DI container be used inside of a Rc BREAKING CHANGE: The DI container is to be used inside of a Rc & it also no longer implements Default --- examples/basic/bootstrap.rs | 5 +++-- examples/factory/bootstrap.rs | 5 +++-- examples/generics/bootstrap.rs | 4 +++- examples/named/bootstrap.rs | 6 ++++-- examples/unbound/bootstrap.rs | 6 ++++-- examples/with-3rd-party/bootstrap.rs | 5 +++-- 6 files changed, 20 insertions(+), 11 deletions(-) (limited to 'examples') diff --git a/examples/basic/bootstrap.rs b/examples/basic/bootstrap.rs index 4e02dc3..30f6df3 100644 --- a/examples/basic/bootstrap.rs +++ b/examples/basic/bootstrap.rs @@ -1,4 +1,5 @@ use std::error::Error; +use std::rc::Rc; use syrette::DIContainer; @@ -12,9 +13,9 @@ use crate::interfaces::cat::ICat; use crate::interfaces::dog::IDog; use crate::interfaces::human::IHuman; -pub fn bootstrap() -> Result> +pub fn bootstrap() -> Result, Box> { - let mut di_container: DIContainer = DIContainer::new(); + let mut di_container = DIContainer::new(); di_container .bind::() diff --git a/examples/factory/bootstrap.rs b/examples/factory/bootstrap.rs index ad8c4d3..19fad81 100644 --- a/examples/factory/bootstrap.rs +++ b/examples/factory/bootstrap.rs @@ -1,4 +1,5 @@ use std::error::Error; +use std::rc::Rc; use syrette::ptr::TransientPtr; use syrette::DIContainer; @@ -11,9 +12,9 @@ use crate::interfaces::user_manager::IUserManager; use crate::user::User; use crate::user_manager::UserManager; -pub fn bootstrap() -> Result> +pub fn bootstrap() -> Result, Box> { - let mut di_container: DIContainer = DIContainer::new(); + let mut di_container = DIContainer::new(); di_container .bind::() diff --git a/examples/generics/bootstrap.rs b/examples/generics/bootstrap.rs index 072350e..752a39b 100644 --- a/examples/generics/bootstrap.rs +++ b/examples/generics/bootstrap.rs @@ -1,3 +1,5 @@ +use std::rc::Rc; + use syrette::{di_container_bind, DIContainer}; // Interfaces @@ -6,7 +8,7 @@ use crate::interfaces::printer::IPrinter; // Implementations use crate::printer::Printer; -pub fn bootstrap() -> DIContainer +pub fn bootstrap() -> Rc { let mut di_container = DIContainer::new(); diff --git a/examples/named/bootstrap.rs b/examples/named/bootstrap.rs index b5fa39d..5f63b47 100644 --- a/examples/named/bootstrap.rs +++ b/examples/named/bootstrap.rs @@ -1,3 +1,5 @@ +use std::rc::Rc; + use anyhow::Result; use syrette::DIContainer; @@ -7,9 +9,9 @@ use crate::katana::Katana; use crate::ninja::Ninja; use crate::shuriken::Shuriken; -pub fn bootstrap() -> Result +pub fn bootstrap() -> Result> { - let mut di_container: DIContainer = DIContainer::new(); + let mut di_container = DIContainer::new(); di_container .bind::() diff --git a/examples/unbound/bootstrap.rs b/examples/unbound/bootstrap.rs index 30366a6..8df6678 100644 --- a/examples/unbound/bootstrap.rs +++ b/examples/unbound/bootstrap.rs @@ -1,3 +1,5 @@ +use std::rc::Rc; + use anyhow::Result; use syrette::DIContainer; @@ -11,9 +13,9 @@ use crate::interfaces::animal_store::IAnimalStore; use crate::interfaces::dog::IDog; use crate::interfaces::human::IHuman; -pub fn bootstrap() -> Result +pub fn bootstrap() -> Result> { - let mut di_container: DIContainer = DIContainer::new(); + let mut di_container = DIContainer::new(); di_container .bind::() diff --git a/examples/with-3rd-party/bootstrap.rs b/examples/with-3rd-party/bootstrap.rs index 49de7fa..a4bd84a 100644 --- a/examples/with-3rd-party/bootstrap.rs +++ b/examples/with-3rd-party/bootstrap.rs @@ -1,4 +1,5 @@ use std::error::Error; +use std::rc::Rc; use syrette::ptr::TransientPtr; use syrette::{declare_default_factory, DIContainer}; @@ -12,9 +13,9 @@ use crate::ninja::Ninja; declare_default_factory!(Shuriken); -pub fn bootstrap() -> Result> +pub fn bootstrap() -> Result, Box> { - let mut di_container: DIContainer = DIContainer::new(); + let mut di_container = DIContainer::new(); di_container.bind::().to::()?; -- cgit v1.2.3-18-g5258