Dependency Injection (DI) and Inversion of Control (IoC) are vital concepts in modern C# development. They help improve code maintainability, testability, and flexibility. Below are 30 multiple-choice questions (MCQs) on these topics, divided into relevant sections. These questions cover DI fundamentals, IoC containers like Unity and Autofac, different injection methods, and the benefits of DI in C# development.
| Qno | Answer |
|---|---|
| 1 | A) A design pattern |
| 2 | B) To decouple objects |
| 3 | B) Constructor Injection |
| 4 | A) Tight coupling between classes |
| 5 | C) Decreases code complexity |
| 6 | D) All of the above |
| 7 | B) Allows mocking of dependencies |
| 8 | A) Control over the flow of the program is transferred to a container |
| 9 | D) Both A and B |
| 10 | B) Internal class dependencies |
| 11 | D) All of the above |
| 12 | B) A Dependency Injection container |
| 13 | A) A high-performance DI container |
| 14 | A) It allows object creation and dependency management |
| 15 | D) All of the above |
| 16 | C) Both Unity and Autofac |
| 17 | A) They support registering components by interface |
| 18 | B) Managing and resolving object dependencies |
| 19 | C) By calling container methods at runtime |
| 20 | C) Autofac |
| 21 | C) Passing dependencies through the class constructor |
| 22 | B) Dependencies are passed through public properties |
| 23 | A) When dependencies need to be injected at runtime |
| 24 | C) Property Injection |
| 25 | B) Ensures that all dependencies are available when the object is created |
| 26 | B) When dependencies can be set later in the object’s lifecycle |
| 27 | C) Dependencies are passed through methods rather than constructors or properties |
| 28 | A) Constructor Injection |
| 29 | A) Constructor Injection |
| 30 | A) It can lead to incomplete object states if dependencies are not set |