1
public class PageBase : System.Web.UI.Page
2
{
3
protected BindingFlags BINDING_FLAGS_SET
4
= BindingFlags.Public
5
| BindingFlags.SetProperty
6
| BindingFlags.Instance
7
| BindingFlags.SetField
8
;
9![](/Images/OutliningIndicators/InBlock.gif)
10
protected override void OnInit(EventArgs e)
11
{
12
IWindsorContainer container = ObtainContainer();
13![](/Images/OutliningIndicators/InBlock.gif)
14
Type type = this.GetType();
15![](/Images/OutliningIndicators/InBlock.gif)
16
PropertyInfo[] properties = type.GetProperties(BINDING_FLAGS_SET);
17![](/Images/OutliningIndicators/InBlock.gif)
18
foreach (PropertyInfo propertie in properties)
19
{
20
string pname = propertie.Name;
21![](/Images/OutliningIndicators/InBlock.gif)
22
if (container.Kernel.HasComponent(pname))
23
{
24
propertie.SetValue(this, container[pname], null);
25
}
26
}
27![](/Images/OutliningIndicators/InBlock.gif)
28
base.OnInit(e);
29
}
30![](/Images/OutliningIndicators/InBlock.gif)
31![](/Images/OutliningIndicators/InBlock.gif)
32
public IWindsorContainer ObtainContainer()
33
{
34![](/Images/OutliningIndicators/InBlock.gif)
35
IContainerAccessor containerAccessor =
36![](/Images/OutliningIndicators/InBlock.gif)
37
HttpContext.Current.ApplicationInstance as IContainerAccessor;
38
if (containerAccessor == null)
39
{
40
throw new ApplicationException("你必须在HttpApplication中实现接口 IContainerAccessor 暴露容器的属性");
41
}
42![](/Images/OutliningIndicators/InBlock.gif)
43
IWindsorContainer container = containerAccessor.Container;
44
if (container == null)
45
{
46
throw new ApplicationException("HttpApplication 得不到容器的实例");
47
}
48
return container;
49
}
50
}
![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
3
![](/Images/OutliningIndicators/InBlock.gif)
4
![](/Images/OutliningIndicators/InBlock.gif)
5
![](/Images/OutliningIndicators/InBlock.gif)
6
![](/Images/OutliningIndicators/InBlock.gif)
7
![](/Images/OutliningIndicators/InBlock.gif)
8
![](/Images/OutliningIndicators/InBlock.gif)
9
![](/Images/OutliningIndicators/InBlock.gif)
10
![](/Images/OutliningIndicators/InBlock.gif)
11
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
12
![](/Images/OutliningIndicators/InBlock.gif)
13
![](/Images/OutliningIndicators/InBlock.gif)
14
![](/Images/OutliningIndicators/InBlock.gif)
15
![](/Images/OutliningIndicators/InBlock.gif)
16
![](/Images/OutliningIndicators/InBlock.gif)
17
![](/Images/OutliningIndicators/InBlock.gif)
18
![](/Images/OutliningIndicators/InBlock.gif)
19
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
20
![](/Images/OutliningIndicators/InBlock.gif)
21
![](/Images/OutliningIndicators/InBlock.gif)
22
![](/Images/OutliningIndicators/InBlock.gif)
23
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
24
![](/Images/OutliningIndicators/InBlock.gif)
25
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
26
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
27
![](/Images/OutliningIndicators/InBlock.gif)
28
![](/Images/OutliningIndicators/InBlock.gif)
29
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
30
![](/Images/OutliningIndicators/InBlock.gif)
31
![](/Images/OutliningIndicators/InBlock.gif)
32
![](/Images/OutliningIndicators/InBlock.gif)
33
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
34
![](/Images/OutliningIndicators/InBlock.gif)
35
![](/Images/OutliningIndicators/InBlock.gif)
36
![](/Images/OutliningIndicators/InBlock.gif)
37
![](/Images/OutliningIndicators/InBlock.gif)
38
![](/Images/OutliningIndicators/InBlock.gif)
39
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
40
![](/Images/OutliningIndicators/InBlock.gif)
41
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
42
![](/Images/OutliningIndicators/InBlock.gif)
43
![](/Images/OutliningIndicators/InBlock.gif)
44
![](/Images/OutliningIndicators/InBlock.gif)
45
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
46
![](/Images/OutliningIndicators/InBlock.gif)
47
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
48
![](/Images/OutliningIndicators/InBlock.gif)
49
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
50
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)