Dependency Injection

Created at 30 Mar 2022, 21:41
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
SE

seankiaa

Joined 02.02.2022

Dependency Injection
30 Mar 2022, 21:41


Hi, 

 

I am wondering how would one design their cTrader bot to avoid code spagetti. I would like to have the business logic in another layer but have no idea how to benefit from Dependency Injection in cBot and cAlgo c# code. Any ideas or examples would be appreciated! 


@seankiaa
Replies

amusleh
31 Mar 2022, 09:58

Hi,

You can put your business logic on another source file or even another assembly, and then use it on your cBot/Indicator.

You can create a wrapper interface around your cBot/Indicator class and inject it to other services that are located on other assemblies, this way you can use dependency injection and also you can perform unit testes by mocking the wrapper interface.

 

 


@amusleh