C# में Dependency Injection का Concept Loosely Coupled Code के Development को Enable करने के लिए Introduced किया गया था। Loosely Coupled Code को Easily Maintained और Reused किया जा सकता है।
C# में Dependency Injection के निम्न Types हैं।
Constructor Injection
Dependencies Inject करने के लिए, Constructor Injection Parameters का उपयोग करता है। यह तब Useful होता है जब एक Class को One या More Dependencies की आवश्यकता होती है।
Setter Injection
Setter Injection का उपयोग करने से पहले Null Check करें। यह Resources और Services को Required के रूप में Create करने की अनुमति देता है।
Method Injection
Injection का यह Type Dependency को Single Method में Inject करता है, जिसे उस Method द्वारा Utilized किया जाता है।