1
|
|
#region Copyright
|
2
|
|
|
3
|
|
|
4
|
|
|
5
|
|
|
6
|
|
|
7
|
|
|
8
|
|
|
9
|
|
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
|
16
|
|
|
17
|
|
#endregion
|
18
|
|
|
19
|
|
using System;
|
20
|
|
using Seasar.Framework.Container.Util;
|
21
|
|
|
22
|
|
namespace Seasar.Framework.Container.Deployer
|
23
|
|
{
|
24
|
|
|
25
|
|
|
26
|
|
|
27
|
|
public class SingletonComponentDeployer : AbstractComponentDeployer
|
28
|
|
{
|
29
|
|
private object component_;
|
30
|
|
private bool instantiating_ = false;
|
31
|
|
|
32
|
447
|
public SingletonComponentDeployer(IComponentDef componentDef)
|
33
|
|
: base(componentDef)
|
34
|
|
{
|
35
|
|
}
|
36
|
|
|
37
|
829
|
public override object Deploy(Type receiveType)
|
38
|
|
{
|
39
|
829
|
lock(this)
|
40
|
|
{
|
41
|
829
|
if(component_ == null) this.Assemble();
|
42
|
|
|
43
|
828
|
object proxy = GetProxy(receiveType);
|
44
|
828
|
return proxy == null ? component_ : proxy;
|
45
|
|
}
|
46
|
|
}
|
47
|
|
|
48
|
1
|
public override void InjectDependency(object outerComponent)
|
49
|
|
{
|
50
|
1
|
throw new NotSupportedException("InjectDependency");
|
51
|
|
}
|
52
|
|
|
53
|
446
|
private void Assemble()
|
54
|
|
{
|
55
|
0
|
if(instantiating_) throw new CyclicReferenceRuntimeException(
|
56
|
|
this.ComponentDef.ComponentType);
|
57
|
446
|
instantiating_ = true;
|
58
|
446
|
component_ = this.ConstructorAssembler.Assemble();
|
59
|
445
|
instantiating_ = false;
|
60
|
445
|
this.PropertyAssembler.Assemble(component_);
|
61
|
445
|
this.InitMethodAssembler.Assemble(component_);
|
62
|
|
}
|
63
|
|
|
64
|
180
|
public override void Init()
|
65
|
|
{
|
66
|
180
|
this.Deploy(ComponentDef.ComponentType);
|
67
|
|
}
|
68
|
|
|
69
|
139
|
public override void Destroy()
|
70
|
|
{
|
71
|
0
|
if(component_ == null) return;
|
72
|
139
|
this.DestroyMethodAssembler.Assemble(component_);
|
73
|
139
|
component_ = null;
|
74
|
|
}
|
75
|
|
|
76
|
|
|
77
|
|
}
|
78
|
|
}
|
79
|
|
|