---
title: "DefaultSingletonBeanRegistry"
author: "baitian"
date: "2012-12-10T17:02:15Z"
tags: []
categories: ["编程语言"]
slug: "defaultsingletonbeanregistry"
draft: false
lastmod: "2012-12-10T17:02:15Z"
id: 1745131
url: "https://baitian.iteye.com/blog/1745131"
---

earlySingletonObjects: contains bean haven't been injected.
dependentBeanMap: <bean -- set bean called the key bean>
dependenciesForBeanMap: <bean -- set bean  be called by the key bean>
containedBeanMap: <bean -- set bean be contained>
desposableBeans: <bean -- bean that actually exec destroy function >

1.add 
1.1 addSingleton
	add to singletonObjects
	remove from singletonFactories
	remove from earlySingletonObjects
	add to registeredSingletons
1.2 addSingletonFactory: resolve circular references
if singletonObjects not contains then bean,then
	remove from singletonFactories
	remove from earlySingletonObjects
	add to registeredSingletons
end if;


1.3 registerDisposableBean
add to disposableBeans,

1.4 registerDependentBean
add to dependentBeanMap
add to dependenciesForBeanMap

1.5 registerContainedBean
add to containedBeanMap
add to dependentBeanMap
add to dependenciesForBeanMap


2.get
2.1 get with ObjectFactory
search singletonObjects
if singletonObjects not have , then
	call beforeSingletonCreation
	get from ObjectFactory
	call afterSingletonCreation
	add to singletonObjects
	remove from singletonFactories
	remove from earlySingletonObjects
	add to registeredSingletons
end if;
2.2 get with none ObjectFactory
search singletonObjects
if singletonObjects not have ,then
	search earlySingletonObjects 
	if not have , then
		get from ObjectFactory
		add to earlySingletonObjects
		remove from singletonFactories
		add to singletonObjects
	end if;
end if;

3.select if exists
search singletonObjects

4.destory
4.1 destory single element
remove from singletonObjects
remove from singleFactories
remove from earlySingletonObjects
remove from registeredSingletons
remove from disposableBeans
destory beans that called this bean
destory this
destory contained beans
remove from dependentBeanMap (remove reference for this bean called)
remove from dependenciesForBeanMap