More working tests.
[castle.git] / InversionOfControl / Castle.Windsor / IWindsorContainer.cs
blob07e5f142fac88e70d2c76d73723f4bf2a3386904
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.Windsor
17 using System;
18 using System.Collections;
19 using Castle.Core;
20 using Castle.MicroKernel;
21 using Castle.MicroKernel.Registration;
23 /// <summary>
24 /// The <c>IWindsorContainer</c> interface exposes all the
25 /// functionality the Windsor implements.
26 /// </summary>
27 public interface IWindsorContainer : IServiceProviderEx, IDisposable
29 /// <summary>
30 /// Gets the container's name
31 /// </summary>
32 /// <remarks>
33 /// Only useful when child containers are being used
34 /// </remarks>
35 /// <value>The container's name.</value>
36 string Name { get; }
38 /// <summary>
39 /// Registers a facility within the kernel.
40 /// </summary>
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);
45 /// <summary>
46 /// Adds a component to be managed by the container
47 /// </summary>
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);
52 /// <summary>
53 /// Adds a component to be managed by the container
54 /// </summary>
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);
60 /// <summary>
61 /// Adds a component to be managed by the container
62 /// </summary>
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);
68 /// <summary>
69 /// Adds a component to be managed by the container
70 /// </summary>
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);
77 /// <summary>
78 /// Adds a concrete class as a component and specify the extended properties.
79 /// Used by facilities, mostly.
80 /// </summary>
81 /// <param name="key"></param>
82 /// <param name="classType"></param>
83 /// <param name="extendedProperties"></param>
84 IWindsorContainer AddComponentWithProperties(String key, Type classType, IDictionary extendedProperties);
86 /// <summary>
87 /// Adds a concrete class and an interface
88 /// as a component and specify the extended properties.
89 /// Used by facilities, mostly.
90 /// </summary>
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);
97 /// <summary>
98 /// Adds a component to be managed by the container.
99 /// The key to obtain the component will be the FullName of the type.
100 /// </summary>
101 /// <typeparam name="T">The <see cref="Type"/> to manage.</typeparam>
102 IWindsorContainer AddComponent<T>();
104 /// <summary>
105 /// Adds a component to be managed by the container
106 /// </summary>
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);
111 /// <summary>
112 /// Adds a component to be managed by the container.
113 /// The key to obtain the component will be the FullName of the type.
114 /// </summary>
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);
119 /// <summary>
120 /// Adds a component to be managed by the container
121 /// </summary>
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);
127 /// <summary>
128 /// Adds a component to be managed by the container
129 /// The key to obtain the component will be the FullName of the type.
130 /// </summary>
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;
135 /// <summary>
136 /// Adds a component to be managed by the container
137 /// </summary>
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;
143 /// <summary>
144 /// Adds a component to be managed by the container
145 /// The key to obtain the component will be the FullName of the type.
146 /// </summary>
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;
152 /// <summary>
153 /// Adds a component to be managed by the container
154 /// </summary>
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;
161 /// <summary>
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.
165 /// </summary>
166 /// <typeparam name="T"></typeparam>
167 /// <param name="extendedProperties"></param>
168 IWindsorContainer AddComponentWithProperties<T>(IDictionary extendedProperties);
170 /// <summary>
171 /// Adds a concrete class as a component and specify the extended properties.
172 /// Used by facilities, mostly.
173 /// </summary>
174 /// <typeparam name="T"></typeparam>
175 /// <param name="key"></param>
176 /// <param name="extendedProperties"></param>
177 IWindsorContainer AddComponentWithProperties<T>(String key, IDictionary extendedProperties);
179 /// <summary>
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.
184 /// </summary>
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;
190 /// <summary>
191 /// Adds a concrete class and an interface
192 /// as a component and specify the extended properties.
193 /// Used by facilities, mostly.
194 /// </summary>
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;
201 /// <summary>
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>
206 /// </summary>
207 IWindsorContainer Register(params IComponentRegistration[] registrations);
209 /// <summary>
210 /// Returns a component instance by the key
211 /// </summary>
212 /// <param name="key"></param>
213 /// <returns></returns>
214 object Resolve(String key);
216 /// <summary>
217 /// Returns a component instance by the key
218 /// </summary>
219 /// <param name="key"></param>
220 /// <param name="arguments"></param>
221 /// <returns></returns>
222 object Resolve(String key, IDictionary arguments);
224 /// <summary>
225 /// Returns a component instance by the key
226 /// </summary>
227 /// <param name="key"></param>
228 /// <param name="argumentsAsAnonymousType"></param>
229 /// <returns></returns>
230 object Resolve(String key, object argumentsAsAnonymousType);
232 /// <summary>
233 /// Returns a component instance by the key
234 /// </summary>
235 /// <param name="key"></param>
236 /// <param name="service"></param>
237 /// <returns></returns>
238 object Resolve(String key, Type service);
240 /// <summary>
241 /// Returns a component instance by the service
242 /// </summary>
243 /// <param name="service"></param>
244 /// <returns></returns>
245 object Resolve(Type service);
247 /// <summary>
248 /// Returns a component instance by the service
249 /// </summary>
250 /// <param name="service"></param>
251 /// <param name="arguments"></param>
252 /// <returns></returns>
253 object Resolve(Type service, IDictionary arguments);
255 /// <summary>
256 /// Returns a component instance by the service
257 /// </summary>
258 /// <param name="service"></param>
259 /// <param name="argumentsAsAnonymousType"></param>
260 /// <returns></returns>
261 object Resolve(Type service, object argumentsAsAnonymousType);
263 /// <summary>
264 /// Releases a component instance
265 /// </summary>
266 /// <param name="instance"></param>
267 void Release(object instance);
269 /// <summary>
270 /// Registers a subcontainer. The components exposed
271 /// by this container will be accessible from subcontainers.
272 /// </summary>
273 /// <param name="childContainer"></param>
274 void AddChildContainer(IWindsorContainer childContainer);
276 /// <summary>
277 /// Remove a child container
278 /// </summary>
279 /// <param name="childContainer"></param>
280 void RemoveChildContainer(IWindsorContainer childContainer);
282 /// <summary>
283 /// Shortcut to <see cref="Resolve(string)"/>
284 /// </summary>
285 object this [String key] { get; }
287 /// <summary>
288 /// Shortcut to <see cref="Resolve(Type)"/>
289 /// </summary>
290 object this [Type service] { get; }
292 /// <summary>
293 /// Gets a child container instance by name.
294 /// </summary>
295 /// <param name="name">The container's name.</param>
296 /// <returns>The child container instance or null</returns>
297 IWindsorContainer GetChildContainer(string name);
299 /// <summary>
300 /// Returns a component instance by the service
301 /// </summary>
302 /// <typeparam name="T">Service type</typeparam>
303 /// <returns>The component instance</returns>
304 T Resolve<T>();
306 /// <summary>
307 /// Returns a component instance by the service
308 /// </summary>
309 /// <typeparam name="T">Service type</typeparam>
310 /// <param name="arguments"></param>
311 /// <returns>The component instance</returns>
312 T Resolve<T>(IDictionary arguments);
314 /// <summary>
315 /// Returns a component instance by the service
316 /// </summary>
317 /// <typeparam name="T">Service type</typeparam>
318 /// <param name="argumentsAsAnonymousType"></param>
319 /// <returns>The component instance</returns>
320 T Resolve<T>(object argumentsAsAnonymousType);
322 /// <summary>
323 /// Returns a component instance by the key
324 /// </summary>
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);
330 /// <summary>
331 /// Returns a component instance by the key
332 /// </summary>
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);
339 /// <summary>
340 /// Returns a component instance by the key
341 /// </summary>
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);
348 /// <summary>
349 /// Returns a component instance by the key
350 /// </summary>
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);
357 /// <summary>
358 /// Returns a component instance by the key
359 /// </summary>
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);
366 /// <summary>
367 /// Returns the inner instance of the MicroKernel
368 /// </summary>
369 IKernel Kernel { get; }
371 /// <summary>
372 /// Gets or sets the parent container if this instance
373 /// is a sub container.
374 /// </summary>
375 IWindsorContainer Parent { get; set; }
377 /// <summary>
378 /// Resolve all valid components that match this type.
379 /// </summary>
380 /// <typeparam name="T">The service type</typeparam>
381 T[] ResolveAll<T>();
383 /// <summary>
384 /// Resolve all valid components that mathc this service
385 /// <param name="service">the service to match</param>
386 /// </summary>
387 Array ResolveAll(Type service);
389 /// <summary>
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>
393 /// </summary>
394 Array ResolveAll(Type service, IDictionary arguments);
396 /// <summary>
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>
400 /// </summary>
401 Array ResolveAll(Type service, object argumentsAsAnonymousType);
403 /// <summary>
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>
407 /// </summary>
408 T[] ResolveAll<T>(IDictionary arguments);
410 /// <summary>
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>
414 /// </summary>
415 T[] ResolveAll<T>(object argumentsAsAnonymousType);