How to get dependencies in model?
- TonnyVlcek
- Member | 31
Hey,
At first I apologies for that elementary question, but, unfortunately, I haven't been able to find a way how to make this work, even though I tried a good bit of variants.
I need to call some method form different model class inside another model class:
Is there a way how to “inject” AaRepository into BbRepository so I can use Aa's methods? (both of those services are registered in config.neon services)
Basically I have to do exactly the same think like in presenters:
or somehow get the service directly from DI container.
Thank you very much for your answers :)
Last edited by TonnyVlcek (2015-01-03 19:20)
- TonnyVlcek
- Member | 31
Ok, thank you, now I know where was the mistake.
I red that I should use constructor injection in model classes, but it always
gave me a fatal error which was caused by my implementation.
Because of I'm extending from BaseRepository with its __construct method:
I have to use this syntax inside of other model classes:
Now it works how it is supposed to :)
I'm posting this for someone who maybe came across the same problem. Please, in case that this is not correct or best practice, let me know what I can do differently, thanks :)