المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Regarding implementation of Dependency Injection with C#



C# Programming
01-10-2013, 06:01 PM
i never use Dependency Injection in apps. i go through few article with Dependency Injection and found the concept is interesting but believe hard to implement in real life. now i want to implement Dependency Injection in my win form apps.

our company work with many shipping company like UPS, Fedex, Purolator etc for now but in future they have plan to works with many other shipping company. i have developed separate separate class library projects for all those shipping company like UPS, Fedex, Purolator and include those dll into our main form apps. the problem is many time we hard code few things in our code like country code etc.

for example i have one form where 4 buttons are there. like those buttons are "Ship with UPS WorldShip", another button there called "Ship with UPS WebAPI", another button there called "Ship with FedEX Desktop Apps" and another last button called "Ship with Fedex WebAPI".

when user click on UPS WorldShip button then a flat file generate in a folder. when user click on UPS WebAPI button then a request goes to UPS site.

when user click on FedEX WinApps button then a flat file generate in a folder. when user click on FedEX WebAPI button then a request goes to FedEx site.

so what i do now when user click on any button then i call a specific function exist in dll to complete the task.

everything is working fine at my end but the problem is when our company start working with another new shipping company then i have to create another class library for that company.

i said i never use DI ever in my apps and have no experience. so some one guide me how could i handle my situation with DI as a result when a new shipping company will join then i do not have to write any extra code. so guide me how to implement DI in my apps and also guide me with how to handle my situation with sample DI code for guidance.

thanks
tbhattacharjee