Added RedirectUsingNamedRoute
[castle.git] / Core / Castle.Core / Model / ComponentModel.cs
blobe27e8da58f983f9caa40aba63ab0d961b31bfc62
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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.Core
17 using System;
18 using System.Collections;
19 using System.Collections.Specialized;
20 using System.Diagnostics;
21 using Castle.Core.Configuration;
23 #region Enums
25 /// <summary>
26 /// Enumeration used to mark the component's lifestyle.
27 /// </summary>
28 public enum LifestyleType
30 /// <summary>
31 /// No lifestyle specified.
32 /// </summary>
33 Undefined,
34 /// <summary>
35 /// Singleton components are instantiated once, and shared
36 /// between all clients.
37 /// </summary>
38 Singleton,
39 /// <summary>
40 /// Thread components have a unique instance per thread.
41 /// </summary>
42 Thread,
43 /// <summary>
44 /// Transient components are created on demand.
45 /// </summary>
46 Transient,
47 /// <summary>
48 /// Optimization of transient components that keeps
49 /// instance in a pool instead of always creating them.
50 /// </summary>
51 Pooled,
52 /// <summary>
53 /// Any other logic to create/release components.
54 /// </summary>
55 Custom,
56 /// <summary>
57 /// PerWebRequest components are created once per Http Request
58 /// </summary>
59 PerWebRequest
62 /// <summary>
63 ///
64 /// </summary>
65 public enum PropertiesInspectionBehavior
67 Undefined,
68 None,
69 All,
70 DeclaredOnly
73 #endregion
75 /// <summary>
76 /// Represents the collection of information and
77 /// meta information collected about a component.
78 /// </summary>
79 [DebuggerDisplay("{Implementation} / {Service}")]
80 [Serializable]
81 public sealed class ComponentModel : GraphNode
83 public const string SkipRegistration = "skip.registration";
85 #region Fields
86 // Note the use of volatile for fields used in the double checked lock pattern.
87 // This is necessary to ensure the pattern works correctly.
89 /// <summary>Name (key) of the component</summary>
90 private String name;
92 /// <summary>Service exposed</summary>
93 private Type service;
95 /// <summary>Implementation for the service</summary>
96 private Type implementation;
98 /// <summary>Extended properties</summary>
99 [NonSerialized] private volatile IDictionary extended;
101 /// <summary>Lifestyle for the component</summary>
102 private LifestyleType lifestyleType;
104 private PropertiesInspectionBehavior inspectionBehavior;
106 /// <summary>Custom lifestyle, if any</summary>
107 private Type customLifestyle;
109 /// <summary>Custom activator, if any</summary>
110 private Type customComponentActivator;
112 /// <summary>Dependencies the kernel must resolve</summary>
113 private volatile DependencyModelCollection dependencies;
115 /// <summary>All available constructors</summary>
116 private volatile ConstructorCandidateCollection constructors;
118 /// <summary>All potential properties that can be setted by the kernel</summary>
119 private volatile PropertySetCollection properties;
121 //private MethodMetaModelCollection methodMetaModels;
123 /// <summary>Steps of lifecycle</summary>
124 private volatile LifecycleStepCollection lifecycleSteps;
126 /// <summary>External parameters</summary>
127 private volatile ParameterModelCollection parameters;
129 /// <summary>Configuration node associated</summary>
130 private IConfiguration configuration;
132 /// <summary>Interceptors associated</summary>
133 private volatile InterceptorReferenceCollection interceptors;
135 /// <summary>/// Custom dependencies/// </summary>
136 [NonSerialized] private IDictionary customDependencies;
138 private bool requiresGenericArguments;
140 #endregion
142 /// <summary>
143 /// Constructs a ComponentModel
144 /// </summary>
145 public ComponentModel(String name, Type service, Type implementation)
147 this.name = name;
148 this.service = service;
149 this.implementation = implementation;
150 lifestyleType = LifestyleType.Undefined;
151 inspectionBehavior = PropertiesInspectionBehavior.Undefined;
154 /// <summary>
155 /// Sets or returns the component key
156 /// </summary>
157 public String Name
159 get { return name; }
160 set { name = value; }
163 /// <summary>
164 /// Gets or sets the service exposed.
165 /// </summary>
166 /// <value>The service.</value>
167 public Type Service
169 get { return service; }
170 set { service = value; }
173 /// <summary>
174 /// Gets or sets the component implementation.
175 /// </summary>
176 /// <value>The implementation.</value>
177 public Type Implementation
179 get { return implementation; }
180 set { implementation = value; }
183 /// <summary>
184 /// Gets or sets a value indicating whether the component requires generic arguments.
185 /// </summary>
186 /// <value>
187 /// <c>true</c> if generic arguments are required; otherwise, <c>false</c>.
188 /// </value>
189 public bool RequiresGenericArguments
191 get { return requiresGenericArguments; }
192 set { requiresGenericArguments = value; }
195 /// <summary>
196 /// Gets or sets the extended properties.
197 /// </summary>
198 /// <value>The extended properties.</value>
199 public IDictionary ExtendedProperties
203 if (extended == null)
205 lock (this)
207 if (extended == null) extended = new HybridDictionary();
210 return extended;
212 set { extended = value; }
215 /// <summary>
216 /// Gets the constructors candidates.
217 /// </summary>
218 /// <value>The constructors.</value>
219 public ConstructorCandidateCollection Constructors
223 if (constructors == null)
225 lock (this)
227 if (constructors == null) constructors = new ConstructorCandidateCollection();
230 return constructors;
234 /// <summary>
235 /// Gets the properties set.
236 /// </summary>
237 /// <value>The properties.</value>
238 public PropertySetCollection Properties
242 if (properties == null)
244 lock (this)
246 if (properties == null) properties = new PropertySetCollection();
249 return properties;
253 /// <summary>
254 /// Gets or sets the configuration.
255 /// </summary>
256 /// <value>The configuration.</value>
257 public IConfiguration Configuration
259 get { return configuration; }
260 set { configuration = value; }
263 /// <summary>
264 /// Gets the lifecycle steps.
265 /// </summary>
266 /// <value>The lifecycle steps.</value>
267 public LifecycleStepCollection LifecycleSteps
271 if (lifecycleSteps == null)
273 lock (this)
275 if (lifecycleSteps == null) lifecycleSteps = new LifecycleStepCollection();
278 return lifecycleSteps;
282 /// <summary>
283 /// Gets or sets the lifestyle type.
284 /// </summary>
285 /// <value>The type of the lifestyle.</value>
286 public LifestyleType LifestyleType
288 get { return lifestyleType; }
289 set { lifestyleType = value; }
292 /// <summary>
293 /// Gets or sets the strategy for
294 /// inspecting public properties
295 /// on the components
296 /// </summary>
297 public PropertiesInspectionBehavior InspectionBehavior
299 get { return inspectionBehavior; }
300 set { inspectionBehavior = value; }
303 /// <summary>
304 /// Gets or sets the custom lifestyle.
305 /// </summary>
306 /// <value>The custom lifestyle.</value>
307 public Type CustomLifestyle
309 get { return customLifestyle; }
310 set { customLifestyle = value; }
313 /// <summary>
314 /// Gets or sets the custom component activator.
315 /// </summary>
316 /// <value>The custom component activator.</value>
317 public Type CustomComponentActivator
319 get { return customComponentActivator; }
320 set { customComponentActivator = value; }
323 /// <summary>
324 /// Gets the interceptors.
325 /// </summary>
326 /// <value>The interceptors.</value>
327 public InterceptorReferenceCollection Interceptors
331 if (interceptors == null)
333 lock (this)
335 if (interceptors == null) interceptors = new InterceptorReferenceCollection();
338 return interceptors;
342 /// <summary>
343 /// Gets the parameter collection.
344 /// </summary>
345 /// <value>The parameters.</value>
346 public ParameterModelCollection Parameters
350 if (parameters == null)
352 lock (this)
354 if (parameters == null) parameters = new ParameterModelCollection();
357 return parameters;
361 /// <summary>
362 /// Dependencies are kept within constructors and
363 /// properties. Others dependencies must be
364 /// registered here, so the kernel (as a matter
365 /// of fact the handler) can check them
366 /// </summary>
367 public DependencyModelCollection Dependencies
371 if (dependencies == null)
373 lock (this)
375 if (dependencies == null) dependencies = new DependencyModelCollection();
378 return dependencies;
382 /// <summary>
383 /// Gets or sets the custom dependencies.
384 /// </summary>
385 /// <value>The custom dependencies.</value>
386 public IDictionary CustomDependencies
390 lock (this)
392 if (customDependencies == null) customDependencies = new HybridDictionary();
394 return customDependencies;
396 set { customDependencies = value; }