Can an object created in an IoC container be called Singleton. If not, why?

can an object created in an IOC container be called Singleton, if so, why, if not, why?

Can someone explain to me in detail in simple words how the IOC conatiner accurately manipulates objects.

+4
source share
5 answers

We can say that spring singleton is not solitary.

Singleton has its own significant scope, spring singleton is a spring ioc container. And the classic singleton significant volume - ClassLoader. You can find more about the difference between these types of singleton here: A spring singleton is nothing .

Spring manages its singleton in a hash map (Singleton Cache). When you get the bean from the ioc spring container, it first checks if the bean exists in the singleton cache, if so, it returns a bean from the singleton cache

+6
source

Spring (and other ioc containers) offer different applications. One of the areas is singleton, i.e. The container creates an instance of the object only once and gives / introduces only one instance. Singleton is the default area, so most beans are really single point in terms of container, meaning they only have one instance.

However, there are other areas, such as prototype or request and session web pages.

When managing a bean, a container does the following:

  • calls the @PostConstruct and @PreDestroy methods (or the init and destroy methods configured by any available means)
  • introduces all its defined dependencies (= installs other beans existing in the container in the fields of this bean)
  • creates AOP aspects around bean methods

Note. You can create multiple class objects that are defined as a singleton bean. A container creates an instance of an object only once, but your code is not limited to several instances.

+1
source
0
source

can an object created in the IOC container be called Singleton if yes why, if not, why?

Read this , from the Spring reference.

Can someone explain to me in detail in simple words how the IOC conatiner precisely manages objects.

Read this from the Spring reference.

0
source

I use the more general definition of Singleton:

Singleton is an object that is guaranteed to be unique within a given sphere.

This volume is ClassLoader in the traditional definition of single-user mode, but other possible areas are:

  • Application (can be grouped, and therefore the classic singleton will not help)
  • HTTP session
  • Theme (implemented through ThreadLocals)
  • HTTP request, etc.

(I really like the Seam Component.getInstance method (class, ScopeType) , which allows you to select the area for which you want to use singleton.)

0
source

All Articles