What is Inversion of Control (IoC) and how does the Spring IoC Container work? इनवर्ज़न ऑफ़ कंट्रोल (IoC) क्या है और स्प्रिंग IoC कंटेनर कैसे काम करता है?
Inversion of Control is the broader principle behind DI: control over object creation and wiring is inverted from the application code to a framework/container. Instead of a class controlling when and how its dependencies are constructed, the Spring IoC Container owns that responsibility.
The container, represented by ApplicationContext, reads bean definitions (from annotations, Java config, or XML), instantiates beans, resolves their dependencies, and manages their full lifecycle. This is why Spring applications are described as having their control "inverted" — the framework calls your code, not the other way around.
ApplicationContext context = SpringApplication.run(DemoApplication.class, args);
OrderService orderService = context.getBean(OrderService.class);इनवर्ज़न ऑफ़ कंट्रोल DI के पीछे का व्यापक सिद्धांत है: ऑब्जेक्ट बनाने और वायर करने का नियंत्रण एप्लिकेशन कोड से एक फ्रेमवर्क/कंटेनर की ओर उलट दिया जाता है। स्प्रिंग IoC कंटेनर यह ज़िम्मेदारी संभालता है।
कंटेनर, जिसे ApplicationContext से दर्शाया जाता है, बीन डेफिनिशन पढ़ता है, बीन्स इंस्टैंशिएट करता है, उनकी डिपेंडेंसीज़ रिज़ॉल्व करता है, और उनके पूरे लाइफसाइकल को मैनेज करता है।
ApplicationContext context = SpringApplication.run(DemoApplication.class, args);
OrderService orderService = context.getBean(OrderService.class);Was this answer clear?