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 System.Reflection;
|
21
|
|
using Seasar.Framework.Util;
|
22
|
|
using Seasar.Framework.Container.Util;
|
23
|
|
|
24
|
|
namespace Seasar.Framework.Container.Assembler
|
25
|
|
{
|
26
|
|
|
27
|
|
|
28
|
|
|
29
|
|
public class AutoConstructorAssembler : AbstractConstructorAssembler
|
30
|
|
{
|
31
|
334
|
public AutoConstructorAssembler(IComponentDef componentDef)
|
32
|
|
: base(componentDef)
|
33
|
|
{
|
34
|
|
}
|
35
|
|
|
36
|
331
|
public override object Assemble()
|
37
|
|
{
|
38
|
331
|
ConstructorInfo constructor =this.GetSuitableConstructor();
|
39
|
331
|
object obj;
|
40
|
331
|
if(constructor == null)
|
41
|
|
{
|
42
|
317
|
if(this.ComponentDef.ComponentType.IsInterface)
|
43
|
|
{
|
44
|
4
|
obj = new object();
|
45
|
|
}
|
46
|
|
else
|
47
|
|
{
|
48
|
313
|
return this.AssembleDefault();
|
49
|
|
}
|
50
|
|
}
|
51
|
|
else
|
52
|
|
{
|
53
|
14
|
object[] args = this.GetArgs(
|
54
|
|
ParameterUtil.GetParameterTypes(constructor.GetParameters()));
|
55
|
13
|
obj = ConstructorUtil.NewInstance(constructor,args);
|
56
|
|
}
|
57
|
17
|
if(this.ComponentDef.ComponentType.IsInterface && this.ComponentDef.AspectDefSize > 0)
|
58
|
|
{
|
59
|
4
|
AopProxyUtil.WeaveAspect(ref obj,this.ComponentDef);
|
60
|
|
}
|
61
|
17
|
return obj;
|
62
|
|
}
|
63
|
|
|
64
|
331
|
private ConstructorInfo GetSuitableConstructor()
|
65
|
|
{
|
66
|
331
|
int argSize = -1;
|
67
|
331
|
ConstructorInfo constructor = null;
|
68
|
331
|
ConstructorInfo[] constructors =
|
69
|
|
this.ComponentDef.ComponentType.GetConstructors();
|
70
|
346
|
for(int i = 0; i < constructors.Length; ++i)
|
71
|
|
{
|
72
|
327
|
int tempArgSize = constructors[i].GetParameters().Length;
|
73
|
327
|
if(tempArgSize == 0) return null;
|
74
|
15
|
if(tempArgSize > argSize
|
75
|
|
&& AutoBindingUtil.IsSuitable(constructors[i].GetParameters()))
|
76
|
|
{
|
77
|
14
|
constructor = constructors[i];
|
78
|
14
|
argSize = tempArgSize;
|
79
|
|
}
|
80
|
|
}
|
81
|
19
|
return constructor;
|
82
|
|
}
|
83
|
|
}
|
84
|
|
}
|
85
|
|
|