blob: 03e36e1d155f888658d01acaba7e6165d8dd5430 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#![deny(clippy::all)]
#![deny(clippy::pedantic)]
#![allow(clippy::module_name_repetitions)]
use anyhow::Result;
use tokio::spawn;
mod animals;
mod bootstrap;
mod food;
mod interfaces;
use bootstrap::bootstrap;
use interfaces::dog::IDog;
use interfaces::human::IHuman;
use crate::interfaces::food::IFoodFactory;
#[tokio::main]
async fn main() -> Result<()>
{
println!("Hello, world!");
let di_container = bootstrap().await?;
{
let dog = di_container
.get::<dyn IDog>()
.await?
.threadsafe_singleton()?;
dog.woof();
}
let food_factory = di_container
.get::<IFoodFactory>()
.await?
.threadsafe_factory()?;
let food = food_factory();
food.eat();
spawn(async move {
let human = di_container.get::<dyn IHuman>().await?.transient()?;
human.make_pets_make_sounds();
Ok::<_, anyhow::Error>(())
})
.await??;
Ok(())
}
|