Hello. I slowly master the growth, and decided to write a small application on it in order to better understand the principles of development on it. The problem I had literally immediately. Take, for example, such a spherical architecture in a vacuum, without characteristic 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 } } } Without an IoC container, I can do something like this:
fn bootstrap() -> MyApp { let factory = MyFactory::new(); MyService::new(&factory) } fn main() { let app = bootstrap(); app.run(); } But, naturally, I don’t want every time I change the parameter list in :: new, I’ve had to go into bootstrap and manually redo the application initialization. This is what I want to achieve:
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(); } In principle, whether the macro is important or not. Although, an implementation that will work at compile time rather than execution is even preferable.
Do you already have any practices, or maybe ideas on how to do this in a plant?