aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-09-17 12:57:18 +0200
committerHampusM <hampus@hampusmat.com>2022-09-17 12:57:18 +0200
commite8e48906a3899e71c9c9d86a3d4528cb7d17e5b9 (patch)
tree6c0eea09dff3be733693f0db0f521bd2d1f2a3e5 /examples
parentea0309436b55d72f57478ed6f74bf31d000f5366 (diff)
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
Diffstat (limited to 'examples')
-rw-r--r--examples/basic/bootstrap.rs5
-rw-r--r--examples/factory/bootstrap.rs5
-rw-r--r--examples/generics/bootstrap.rs4
-rw-r--r--examples/named/bootstrap.rs6
-rw-r--r--examples/unbound/bootstrap.rs6
-rw-r--r--examples/with-3rd-party/bootstrap.rs5
6 files changed, 20 insertions, 11 deletions
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<DIContainer, Box<dyn Error>>
+pub fn bootstrap() -> Result<Rc<DIContainer>, Box<dyn Error>>
{
- let mut di_container: DIContainer = DIContainer::new();
+ let mut di_container = DIContainer::new();
di_container
.bind::<dyn IDog>()
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<DIContainer, Box<dyn Error>>
+pub fn bootstrap() -> Result<Rc<DIContainer>, Box<dyn Error>>
{
- let mut di_container: DIContainer = DIContainer::new();
+ let mut di_container = DIContainer::new();
di_container
.bind::<dyn IUserManager>()
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<DIContainer>
{
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<DIContainer>
+pub fn bootstrap() -> Result<Rc<DIContainer>>
{
- let mut di_container: DIContainer = DIContainer::new();
+ let mut di_container = DIContainer::new();
di_container
.bind::<dyn IWeapon>()
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<DIContainer>
+pub fn bootstrap() -> Result<Rc<DIContainer>>
{
- let mut di_container: DIContainer = DIContainer::new();
+ let mut di_container = DIContainer::new();
di_container
.bind::<dyn IDog>()
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<DIContainer, Box<dyn Error>>
+pub fn bootstrap() -> Result<Rc<DIContainer>, Box<dyn Error>>
{
- let mut di_container: DIContainer = DIContainer::new();
+ let mut di_container = DIContainer::new();
di_container.bind::<dyn INinja>().to::<Ninja>()?;