Answer the question
In order to leave comments, you need to log in
How to implement Inversion of Control in Rust?
Hello.
I am slowly learning Rust, and decided to write a small application on it along the way in order to better understand the principles of development on it. My problem arose almost immediately. Let's take for example such a spherical architecture in a vacuum, without the characteristic growing complications:
trait Some {
fn get_id(&self) -> int;
}
trait SomeFactory {
fn create_some(&self) -> &Some
}
struct MyApp {
factory: &SomeFactory
}
impl MyApp {
fn new(f: &SomeFactory) -> MyApp {
MyApp {
factory: f
}
}
}
fn bootstrap() -> MyApp {
let factory = MyFactory::new();
MyService::new(&factory)
}
fn main() {
let app = bootstrap();
app.run();
}
fn bootstrap() -> IoC {
let IoC = IoC::new();
IoC.Register<SomeFactory, MyFactory>();
IoC.Register<SomeApp, MyApp>();
IoC
}
fn main() {
let IoC = bootstrap();
let app = IoC.Resolve<SomeApp>();
app.run();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question