1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.MicroKernel
.ModelBuilder
18 using System
.Collections
;
21 using Castle
.MicroKernel
.ModelBuilder
.Inspectors
;
24 /// Summary description for DefaultComponentModelBuilder.
27 public class DefaultComponentModelBuilder
: IComponentModelBuilder
29 private readonly IKernel kernel
;
30 private readonly ArrayList contributors
;
33 /// Initializes a new instance of the <see cref="DefaultComponentModelBuilder"/> class.
35 /// <param name="kernel">The kernel.</param>
36 public DefaultComponentModelBuilder(IKernel kernel
)
39 contributors
= new ArrayList();
41 InitializeContributors();
45 /// Constructs a new ComponentModel by invoking
46 /// the registered contributors.
48 /// <param name="key"></param>
49 /// <param name="service"></param>
50 /// <param name="classType"></param>
51 /// <param name="extendedProperties"></param>
52 /// <returns></returns>
53 public ComponentModel
BuildModel(String key
, Type service
, Type classType
, IDictionary extendedProperties
)
55 ComponentModel model
= new ComponentModel(key
, service
, classType
);
57 if (extendedProperties
!= null)
59 model
.ExtendedProperties
= extendedProperties
;
62 foreach(IContributeComponentModelConstruction contributor
in contributors
)
64 contributor
.ProcessModel( kernel
, model
);
71 /// Gets the contributors.
73 /// <value>The contributors.</value>
74 public IContributeComponentModelConstruction
[] Contributors
78 return (IContributeComponentModelConstruction
[])
79 contributors
.ToArray(typeof(IContributeComponentModelConstruction
));
84 /// "To give or supply in common with others; give to a
85 /// common fund or for a common purpose". The contributor
86 /// should inspect the component, or even the configuration
87 /// associated with the component, to add or change information
88 /// in the model that can be used later.
90 /// <param name="contributor"></param>
91 public void AddContributor(IContributeComponentModelConstruction contributor
)
93 contributors
.Add(contributor
);
97 /// Removes the specified contributor
99 /// <param name="contributor"></param>
100 public void RemoveContributor(IContributeComponentModelConstruction contributor
)
102 contributors
.Remove(contributor
);
106 /// Initializes the default contributors.
108 protected virtual void InitializeContributors()
110 AddContributor(new GenericInspector());
111 AddContributor(new ConfigurationModelInspector());
112 AddContributor(new ConfigurationParametersInspector());
113 AddContributor(new LifestyleModelInspector());
114 AddContributor(new ConstructorDependenciesModelInspector());
115 AddContributor(new PropertiesDependenciesModelInspector());
116 AddContributor(new LifecycleModelInspector());
117 AddContributor(new InterceptorInspector());
118 AddContributor(new ComponentActivatorInspector());
119 AddContributor(new ComponentProxyInspector());