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
.Windsor
18 using System
.Collections
;
20 using Castle
.MicroKernel
;
21 using Castle
.MicroKernel
.Registration
;
24 /// The <c>IWindsorContainer</c> interface exposes all the
25 /// functionality the Windsor implements.
27 public interface IWindsorContainer
: IServiceProviderEx
, IDisposable
30 /// Gets the container's name
33 /// Only useful when child containers are being used
35 /// <value>The container's name.</value>
39 /// Registers a facility within the kernel.
41 /// <param name="key">The key by which the <see cref="IFacility"/> gets indexed.</param>
42 /// <param name="facility">The <see cref="IFacility"/> to add to the container.</param>
43 IWindsorContainer
AddFacility(String key
, IFacility facility
);
46 /// Adds a component to be managed by the container
48 /// <param name="key">The key by which the component gets indexed.</param>
49 /// <param name="classType">The <see cref="Type"/> to manage.</param>
50 IWindsorContainer
AddComponent(String key
, Type classType
);
53 /// Adds a component to be managed by the container
55 /// <param name="key">The key by which the component gets indexed.</param>
56 /// <param name="serviceType">The service <see cref="Type"/> that the component implements.</param>
57 /// <param name="classType">The <see cref="Type"/> to manage.</param>
58 IWindsorContainer
AddComponent(String key
, Type serviceType
, Type classType
);
61 /// Adds a component to be managed by the container
63 /// <param name="key">The key by which the component gets indexed.</param>
64 /// <param name="classType">The <see cref="Type"/> to manage.</param>
65 /// <param name="lifestyle">The <see cref="LifestyleType"/> with which to manage the component.</param>
66 IWindsorContainer
AddComponentLifeStyle(String key
, Type classType
, LifestyleType lifestyle
);
69 /// Adds a component to be managed by the container
71 /// <param name="key">The key by which the component gets indexed.</param>
72 /// <param name="serviceType">The service <see cref="Type"/> that the component implements.</param>
73 /// <param name="classType">The <see cref="Type"/> to manage.</param>
74 /// <param name="lifestyle">The <see cref="LifestyleType"/> with which to manage the component.</param>
75 IWindsorContainer
AddComponentLifeStyle(String key
, Type serviceType
, Type classType
, LifestyleType lifestyle
);
78 /// Adds a concrete class as a component and specify the extended properties.
79 /// Used by facilities, mostly.
81 /// <param name="key"></param>
82 /// <param name="classType"></param>
83 /// <param name="extendedProperties"></param>
84 IWindsorContainer
AddComponentWithProperties(String key
, Type classType
, IDictionary extendedProperties
);
87 /// Adds a concrete class and an interface
88 /// as a component and specify the extended properties.
89 /// Used by facilities, mostly.
91 /// <param name="key"></param>
92 /// <param name="serviceType"></param>
93 /// <param name="classType"></param>
94 /// <param name="extendedProperties"></param>
95 IWindsorContainer
AddComponentWithProperties(String key
, Type serviceType
, Type classType
, IDictionary extendedProperties
);
98 /// Adds a component to be managed by the container.
99 /// The key to obtain the component will be the FullName of the type.
101 /// <typeparam name="T">The <see cref="Type"/> to manage.</typeparam>
102 IWindsorContainer AddComponent
<T
>();
105 /// Adds a component to be managed by the container
107 /// <typeparam name="T">The <see cref="Type"/> to manage.</typeparam>
108 /// <param name="key">The key by which the component gets indexed.</param>
109 IWindsorContainer AddComponent
<T
>(String key
);
112 /// Adds a component to be managed by the container.
113 /// The key to obtain the component will be the FullName of the type.
115 /// <typeparam name="T">The <see cref="Type"/> to manage.</typeparam>
116 /// <param name="lifestyle">The <see cref="LifestyleType"/> with which to manage the component.</param>
117 IWindsorContainer AddComponentLifeStyle
<T
>(LifestyleType lifestyle
);
120 /// Adds a component to be managed by the container
122 /// <typeparam name="T">The <see cref="Type"/> to manage.</typeparam>
123 /// <param name="key">The key by which the component gets indexed.</param>
124 /// <param name="lifestyle">The <see cref="LifestyleType"/> with which to manage the component.</param>
125 IWindsorContainer AddComponentLifeStyle
<T
>(String key
, LifestyleType lifestyle
);
128 /// Adds a component to be managed by the container
129 /// The key to obtain the component will be the FullName of the type.
131 /// <typeparam name="I">The service <see cref="Type"/> that the component implements.</typeparam>
132 /// <typeparam name="T">The <see cref="Type"/> to manage.</typeparam>
133 IWindsorContainer AddComponent
<I
, T
>() where T
: class;
136 /// Adds a component to be managed by the container
138 /// <typeparam name="I">The service <see cref="Type"/> that the component implements.</typeparam>
139 /// <typeparam name="T">The <see cref="Type"/> to manage.</typeparam>
140 /// <param name="key">The key by which the component gets indexed.</param>
141 IWindsorContainer AddComponent
<I
, T
>(String key
) where T
: class;
144 /// Adds a component to be managed by the container
145 /// The key to obtain the component will be the FullName of the type.
147 /// <typeparam name="I">The service <see cref="Type"/> that the component implements.</typeparam>
148 /// <typeparam name="T">The <see cref="Type"/> to manage.</typeparam>
149 /// <param name="lifestyle">The <see cref="LifestyleType"/> with which to manage the component.</param>
150 IWindsorContainer AddComponentLifeStyle
<I
, T
>(LifestyleType lifestyle
) where T
: class;
153 /// Adds a component to be managed by the container
155 /// <typeparam name="I">The service <see cref="Type"/> that the component implements.</typeparam>
156 /// <typeparam name="T">The <see cref="Type"/> to manage.</typeparam>
157 /// <param name="key">The key by which the component gets indexed.</param>
158 /// <param name="lifestyle">The <see cref="LifestyleType"/> with which to manage the component.</param>
159 IWindsorContainer AddComponentLifeStyle
<I
, T
>(String key
, LifestyleType lifestyle
) where T
: class;
162 /// Adds a concrete class as a component and specify the extended properties.
163 /// Used by facilities, mostly.
164 /// The key to obtain the component will be the FullName of the type.
166 /// <typeparam name="T"></typeparam>
167 /// <param name="extendedProperties"></param>
168 IWindsorContainer AddComponentWithProperties
<T
>(IDictionary extendedProperties
);
171 /// Adds a concrete class as a component and specify the extended properties.
172 /// Used by facilities, mostly.
174 /// <typeparam name="T"></typeparam>
175 /// <param name="key"></param>
176 /// <param name="extendedProperties"></param>
177 IWindsorContainer AddComponentWithProperties
<T
>(String key
, IDictionary extendedProperties
);
180 /// Adds a concrete class and an interface
181 /// as a component and specify the extended properties.
182 /// Used by facilities, mostly.
183 /// The key to obtain the component will be the FullName of the type.
185 /// <typeparam name="I"></typeparam>
186 /// <typeparam name="T"></typeparam>
187 /// <param name="extendedProperties"></param>
188 IWindsorContainer AddComponentLifeStyle
<I
, T
>(IDictionary extendedProperties
) where T
: class;
191 /// Adds a concrete class and an interface
192 /// as a component and specify the extended properties.
193 /// Used by facilities, mostly.
195 /// <typeparam name="I"></typeparam>
196 /// <typeparam name="T"></typeparam>
197 /// <param name="key"></param>
198 /// <param name="extendedProperties"></param>
199 IWindsorContainer AddComponentLifeStyle
<I
, T
>(String key
, IDictionary extendedProperties
) where T
: class;
202 /// Registers the components described by the <see cref="ComponentRegistration{S}"/>s
203 /// with the <see cref="IWindsorContainer"/>.
204 /// <param name="registrations">The component registrations.</param>
205 /// <returns>The container.</returns>
207 IWindsorContainer
Register(params IComponentRegistration
[] registrations
);
210 /// Returns a component instance by the key
212 /// <param name="key"></param>
213 /// <returns></returns>
214 object Resolve(String key
);
217 /// Returns a component instance by the key
219 /// <param name="key"></param>
220 /// <param name="arguments"></param>
221 /// <returns></returns>
222 object Resolve(String key
, IDictionary arguments
);
225 /// Returns a component instance by the key
227 /// <param name="key"></param>
228 /// <param name="argumentsAsAnonymousType"></param>
229 /// <returns></returns>
230 object Resolve(String key
, object argumentsAsAnonymousType
);
233 /// Returns a component instance by the key
235 /// <param name="key"></param>
236 /// <param name="service"></param>
237 /// <returns></returns>
238 object Resolve(String key
, Type service
);
241 /// Returns a component instance by the service
243 /// <param name="service"></param>
244 /// <returns></returns>
245 object Resolve(Type service
);
248 /// Returns a component instance by the service
250 /// <param name="service"></param>
251 /// <param name="arguments"></param>
252 /// <returns></returns>
253 object Resolve(Type service
, IDictionary arguments
);
256 /// Returns a component instance by the service
258 /// <param name="service"></param>
259 /// <param name="argumentsAsAnonymousType"></param>
260 /// <returns></returns>
261 object Resolve(Type service
, object argumentsAsAnonymousType
);
264 /// Releases a component instance
266 /// <param name="instance"></param>
267 void Release(object instance
);
270 /// Registers a subcontainer. The components exposed
271 /// by this container will be accessible from subcontainers.
273 /// <param name="childContainer"></param>
274 void AddChildContainer(IWindsorContainer childContainer
);
277 /// Remove a child container
279 /// <param name="childContainer"></param>
280 void RemoveChildContainer(IWindsorContainer childContainer
);
283 /// Shortcut to <see cref="Resolve(string)"/>
285 object this [String key
] { get; }
288 /// Shortcut to <see cref="Resolve(Type)"/>
290 object this [Type service
] { get; }
293 /// Gets a child container instance by name.
295 /// <param name="name">The container's name.</param>
296 /// <returns>The child container instance or null</returns>
297 IWindsorContainer
GetChildContainer(string name
);
300 /// Returns a component instance by the service
302 /// <typeparam name="T">Service type</typeparam>
303 /// <returns>The component instance</returns>
307 /// Returns a component instance by the service
309 /// <typeparam name="T">Service type</typeparam>
310 /// <param name="arguments"></param>
311 /// <returns>The component instance</returns>
312 T Resolve
<T
>(IDictionary arguments
);
315 /// Returns a component instance by the service
317 /// <typeparam name="T">Service type</typeparam>
318 /// <param name="argumentsAsAnonymousType"></param>
319 /// <returns>The component instance</returns>
320 T Resolve
<T
>(object argumentsAsAnonymousType
);
323 /// Returns a component instance by the key
325 /// <param name="key">Component's key</param>
326 /// <typeparam name="T">Service type</typeparam>
327 /// <returns>The Component instance</returns>
328 T Resolve
<T
>(String key
);
331 /// Returns a component instance by the key
333 /// <typeparam name="T">Service type</typeparam>
334 /// <param name="key">Component's key</param>
335 /// <param name="arguments"></param>
336 /// <returns>The Component instance</returns>
337 T Resolve
<T
>(String key
, IDictionary arguments
);
340 /// Returns a component instance by the key
342 /// <typeparam name="T">Service type</typeparam>
343 /// <param name="key">Component's key</param>
344 /// <param name="argumentsAsAnonymousType"></param>
345 /// <returns>The Component instance</returns>
346 T Resolve
<T
>(String key
, object argumentsAsAnonymousType
);
349 /// Returns a component instance by the key
351 /// <param name="key"></param>
352 /// <param name="service"></param>
353 /// <param name="arguments"></param>
354 /// <returns></returns>
355 object Resolve(String key
, Type service
, IDictionary arguments
);
358 /// Returns a component instance by the key
360 /// <param name="key"></param>
361 /// <param name="service"></param>
362 /// <param name="argumentsAsAnonymousType"></param>
363 /// <returns></returns>
364 object Resolve(String key
, Type service
, object argumentsAsAnonymousType
);
367 /// Returns the inner instance of the MicroKernel
369 IKernel Kernel { get; }
372 /// Gets or sets the parent container if this instance
373 /// is a sub container.
375 IWindsorContainer Parent { get; set; }
378 /// Resolve all valid components that match this type.
380 /// <typeparam name="T">The service type</typeparam>
384 /// Resolve all valid components that mathc this service
385 /// <param name="service">the service to match</param>
387 Array
ResolveAll(Type service
);
390 /// Resolve all valid components that mathc this service
391 /// <param name="service">the service to match</param>
392 /// <param name="arguments">Arguments to resolve the service</param>
394 Array
ResolveAll(Type service
, IDictionary arguments
);
397 /// Resolve all valid components that mathc this service
398 /// <param name="service">the service to match</param>
399 /// <param name="argumentsAsAnonymousType">Arguments to resolve the service</param>
401 Array
ResolveAll(Type service
, object argumentsAsAnonymousType
);
404 /// Resolve all valid components that match this type.
405 /// <typeparam name="T">The service type</typeparam>
406 /// <param name="arguments">Arguments to resolve the service</param>
408 T
[] ResolveAll
<T
>(IDictionary arguments
);
411 /// Resolve all valid components that match this type.
412 /// <typeparam name="T">The service type</typeparam>
413 /// <param name="argumentsAsAnonymousType">Arguments to resolve the service</param>
415 T
[] ResolveAll
<T
>(object argumentsAsAnonymousType
);