Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should be constructed through an IOC container?

How do you determine which classes should be constructed through an IOC container, and which ones shouldn't. I've worked on projects with both extremes and it seems like interfaces should only be used when the classs specifies a specific technoliogy like logging or data access?

Where do people draw the line between the two?

like image 562
Kye Avatar asked Dec 09 '09 09:12

Kye


People also ask

What is use of IoC container?

IoC container is a framework for implementing automated dependency injection. It contains object creation for the longer ways to use and injects dependencies within the class.

What is the use of Spring IoC container?

The Spring IoC Container In the Spring framework, the interface ApplicationContext represents the IoC container. The Spring container is responsible for instantiating, configuring and assembling objects known as beans, as well as managing their life cycles.

What are the types of IoC containers explain them?

There are basically two types of IOC Containers in Spring: BeanFactory: BeanFactory is like a factory class that contains a collection of beans. It instantiates the bean whenever asked for by clients. ApplicationContext: The ApplicationContext interface is built on top of the BeanFactory interface.

Which of the following is a IoC container?

There are two types of IoC containers. They are: BeanFactory. ApplicationContext.


1 Answers

I don't draw any line - the more, the merrier.

What happens is that the more you can manage to split up your API in small units, the closer you get to the Single Responsibility Principle, because everything that hides behind an interface will have a tendency to do only one thing, and do it well.

By injecting interfaces into implementation that implement new interfaces that are injected into other types, etc. you end up with a very flexible structure where you can vary implementation details at almost any level, and each collaborator is pretty simple in itself.

With a good DI Container and some sensible conventions, the DI Container will automatically take care of most of the wiring for you, so the configuration doesn't have to be extreme.

like image 195
Mark Seemann Avatar answered Nov 12 '22 00:11

Mark Seemann