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 container.
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 /// Creates and adds an <see cref="IFacility"/> facility to the container.
48 /// <typeparam name="T">The facility type.</typeparam>
49 /// <param name="key"></param>
50 /// <returns></returns>
51 IWindsorContainer AddFacility
<T
>(String key
) where T
: IFacility
, new();
54 /// Creates and adds an <see cref="IFacility"/> facility to the container.
56 /// <typeparam name="T">The facility type.</typeparam>
57 /// <returns></returns>
58 IWindsorContainer AddFacility
<T
>() where T
: IFacility
, new();
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 IWindsorContainer
AddComponent(String key
, Type classType
);
68 /// Adds a component to be managed by the container
70 /// <param name="key">The key by which the component gets indexed.</param>
71 /// <param name="serviceType">The service <see cref="Type"/> that the component implements.</param>
72 /// <param name="classType">The <see cref="Type"/> to manage.</param>
73 IWindsorContainer
AddComponent(String key
, Type serviceType
, Type classType
);
76 /// Adds a component to be managed by the container
78 /// <param name="key">The key by which the component gets indexed.</param>
79 /// <param name="classType">The <see cref="Type"/> to manage.</param>
80 /// <param name="lifestyle">The <see cref="LifestyleType"/> with which to manage the component.</param>
81 IWindsorContainer
AddComponentLifeStyle(String key
, Type classType
, LifestyleType lifestyle
);
84 /// Adds a component to be managed by the container
86 /// <param name="key">The key by which the component gets indexed.</param>
87 /// <param name="serviceType">The service <see cref="Type"/> that the component implements.</param>
88 /// <param name="classType">The <see cref="Type"/> to manage.</param>
89 /// <param name="lifestyle">The <see cref="LifestyleType"/> with which to manage the component.</param>
90 IWindsorContainer
AddComponentLifeStyle(String key
, Type serviceType
, Type classType
, LifestyleType lifestyle
);
93 /// Adds a concrete class as a component and specify the extended properties.
94 /// Used by facilities, mostly.
96 /// <param name="key"></param>
97 /// <param name="classType"></param>
98 /// <param name="extendedProperties"></param>
99 IWindsorContainer
AddComponentWithProperties(String key
, Type classType
, IDictionary extendedProperties
);
102 /// Adds a concrete class and an interface
103 /// as a component and specify the extended properties.
104 /// Used by facilities, mostly.
106 /// <param name="key"></param>
107 /// <param name="serviceType"></param>
108 /// <param name="classType"></param>
109 /// <param name="extendedProperties"></param>
110 IWindsorContainer
AddComponentWithProperties(String key
, Type serviceType
, Type classType
, IDictionary extendedProperties
);
113 /// Adds a component to be managed by the container.
114 /// The key to obtain the component will be the FullName of the type.
116 /// <typeparam name="T">The <see cref="Type"/> to manage.</typeparam>
117 IWindsorContainer AddComponent
<T
>();
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 IWindsorContainer AddComponent
<T
>(String key
);
127 /// Adds a component to be managed by the container.
128 /// The key to obtain the component will be the FullName of the type.
130 /// <typeparam name="T">The <see cref="Type"/> to manage.</typeparam>
131 /// <param name="lifestyle">The <see cref="LifestyleType"/> with which to manage the component.</param>
132 IWindsorContainer AddComponentLifeStyle
<T
>(LifestyleType lifestyle
);
135 /// Adds a component to be managed by the container
137 /// <typeparam name="T">The <see cref="Type"/> to manage.</typeparam>
138 /// <param name="key">The key by which the component gets indexed.</param>
139 /// <param name="lifestyle">The <see cref="LifestyleType"/> with which to manage the component.</param>
140 IWindsorContainer AddComponentLifeStyle
<T
>(String key
, LifestyleType lifestyle
);
143 /// Adds a component to be managed by the container
144 /// The key to obtain the component will be the FullName of the type.
146 /// <typeparam name="I">The service <see cref="Type"/> that the component implements.</typeparam>
147 /// <typeparam name="T">The <see cref="Type"/> to manage.</typeparam>
148 IWindsorContainer AddComponent
<I
, T
>() where T
: class;
151 /// Adds a component to be managed by the container
153 /// <typeparam name="I">The service <see cref="Type"/> that the component implements.</typeparam>
154 /// <typeparam name="T">The <see cref="Type"/> to manage.</typeparam>
155 /// <param name="key">The key by which the component gets indexed.</param>
156 IWindsorContainer AddComponent
<I
, T
>(String key
) where T
: class;
159 /// Adds a component to be managed by the container
160 /// The key to obtain the component will be the FullName of the type.
162 /// <typeparam name="I">The service <see cref="Type"/> that the component implements.</typeparam>
163 /// <typeparam name="T">The <see cref="Type"/> to manage.</typeparam>
164 /// <param name="lifestyle">The <see cref="LifestyleType"/> with which to manage the component.</param>
165 IWindsorContainer AddComponentLifeStyle
<I
, T
>(LifestyleType lifestyle
) where T
: class;
168 /// Adds a component to be managed by the container
170 /// <typeparam name="I">The service <see cref="Type"/> that the component implements.</typeparam>
171 /// <typeparam name="T">The <see cref="Type"/> to manage.</typeparam>
172 /// <param name="key">The key by which the component gets indexed.</param>
173 /// <param name="lifestyle">The <see cref="LifestyleType"/> with which to manage the component.</param>
174 IWindsorContainer AddComponentLifeStyle
<I
, T
>(String key
, LifestyleType lifestyle
) where T
: class;
177 /// Adds a concrete class as a component and specify the extended properties.
178 /// Used by facilities, mostly.
179 /// The key to obtain the component will be the FullName of the type.
181 /// <typeparam name="T"></typeparam>
182 /// <param name="extendedProperties"></param>
183 IWindsorContainer AddComponentWithProperties
<T
>(IDictionary extendedProperties
);
186 /// Adds a concrete class as a component and specify the extended properties.
187 /// Used by facilities, mostly.
189 /// <typeparam name="T"></typeparam>
190 /// <param name="key"></param>
191 /// <param name="extendedProperties"></param>
192 IWindsorContainer AddComponentWithProperties
<T
>(String key
, IDictionary extendedProperties
);
195 /// Adds a concrete class and an interface
196 /// as a component and specify the extended properties.
197 /// Used by facilities, mostly.
198 /// The key to obtain the component will be the FullName of the type.
200 /// <typeparam name="I"></typeparam>
201 /// <typeparam name="T"></typeparam>
202 /// <param name="extendedProperties"></param>
203 IWindsorContainer AddComponentLifeStyle
<I
, T
>(IDictionary extendedProperties
) where T
: class;
206 /// Adds a concrete class and an interface
207 /// as a component and specify the extended properties.
208 /// Used by facilities, mostly.
210 /// <typeparam name="I"></typeparam>
211 /// <typeparam name="T"></typeparam>
212 /// <param name="key"></param>
213 /// <param name="extendedProperties"></param>
214 IWindsorContainer AddComponentLifeStyle
<I
, T
>(String key
, IDictionary extendedProperties
) where T
: class;
217 /// Registers the components provided by the <see cref="IRegistration"/>s
218 /// with the <see cref="IWindsorContainer"/>.
219 /// <param name="registrations">The component registrations.</param>
220 /// <returns>The container.</returns>
222 IWindsorContainer
Register(params IRegistration
[] registrations
);
225 /// Installs the components provided by the <see cref="IWindsorInstaller"/>s
226 /// with the <see cref="IWindsorContainer"/>.
227 /// <param name="installers">The component installers.</param>
228 /// <returns>The container.</returns>
230 IWindsorContainer
Install(params IWindsorInstaller
[] installers
);
233 /// Returns a component instance by the key
235 /// <param name="key"></param>
236 /// <returns></returns>
237 object Resolve(String key
);
240 /// Returns a component instance by the key
242 /// <param name="key"></param>
243 /// <param name="arguments"></param>
244 /// <returns></returns>
245 object Resolve(String key
, IDictionary arguments
);
248 /// Returns a component instance by the key
250 /// <param name="key"></param>
251 /// <param name="argumentsAsAnonymousType"></param>
252 /// <returns></returns>
253 object Resolve(String key
, object argumentsAsAnonymousType
);
256 /// Returns a component instance by the key
258 /// <param name="key"></param>
259 /// <param name="service"></param>
260 /// <returns></returns>
261 object Resolve(String key
, Type service
);
264 /// Returns a component instance by the service
266 /// <param name="service"></param>
267 /// <returns></returns>
268 object Resolve(Type service
);
271 /// Returns a component instance by the service
273 /// <param name="service"></param>
274 /// <param name="arguments"></param>
275 /// <returns></returns>
276 object Resolve(Type service
, IDictionary arguments
);
279 /// Returns a component instance by the service
281 /// <param name="service"></param>
282 /// <param name="argumentsAsAnonymousType"></param>
283 /// <returns></returns>
284 object Resolve(Type service
, object argumentsAsAnonymousType
);
287 /// Releases a component instance
289 /// <param name="instance"></param>
290 void Release(object instance
);
293 /// Registers a subcontainer. The components exposed
294 /// by this container will be accessible from subcontainers.
296 /// <param name="childContainer"></param>
297 void AddChildContainer(IWindsorContainer childContainer
);
300 /// Remove a child container
302 /// <param name="childContainer"></param>
303 void RemoveChildContainer(IWindsorContainer childContainer
);
306 /// Shortcut to <see cref="Resolve(string)"/>
308 object this [String key
] { get; }
311 /// Shortcut to <see cref="Resolve(Type)"/>
313 object this [Type service
] { get; }
316 /// Gets a child container instance by name.
318 /// <param name="name">The container's name.</param>
319 /// <returns>The child container instance or null</returns>
320 IWindsorContainer
GetChildContainer(string name
);
323 /// Returns a component instance by the service
325 /// <typeparam name="T">Service type</typeparam>
326 /// <returns>The component instance</returns>
330 /// Returns a component instance by the service
332 /// <typeparam name="T">Service type</typeparam>
333 /// <param name="arguments"></param>
334 /// <returns>The component instance</returns>
335 T Resolve
<T
>(IDictionary arguments
);
338 /// Returns a component instance by the service
340 /// <typeparam name="T">Service type</typeparam>
341 /// <param name="argumentsAsAnonymousType"></param>
342 /// <returns>The component instance</returns>
343 T Resolve
<T
>(object argumentsAsAnonymousType
);
346 /// Returns a component instance by the key
348 /// <param name="key">Component's key</param>
349 /// <typeparam name="T">Service type</typeparam>
350 /// <returns>The Component instance</returns>
351 T Resolve
<T
>(String key
);
354 /// Returns a component instance by the key
356 /// <typeparam name="T">Service type</typeparam>
357 /// <param name="key">Component's key</param>
358 /// <param name="arguments"></param>
359 /// <returns>The Component instance</returns>
360 T Resolve
<T
>(String key
, IDictionary arguments
);
363 /// Returns a component instance by the key
365 /// <typeparam name="T">Service type</typeparam>
366 /// <param name="key">Component's key</param>
367 /// <param name="argumentsAsAnonymousType"></param>
368 /// <returns>The Component instance</returns>
369 T Resolve
<T
>(String key
, object argumentsAsAnonymousType
);
372 /// Returns a component instance by the key
374 /// <param name="key"></param>
375 /// <param name="service"></param>
376 /// <param name="arguments"></param>
377 /// <returns></returns>
378 object Resolve(String key
, Type service
, IDictionary arguments
);
381 /// Returns a component instance by the key
383 /// <param name="key"></param>
384 /// <param name="service"></param>
385 /// <param name="argumentsAsAnonymousType"></param>
386 /// <returns></returns>
387 object Resolve(String key
, Type service
, object argumentsAsAnonymousType
);
390 /// Returns the inner instance of the MicroKernel
392 IKernel Kernel { get; }
395 /// Gets or sets the parent container if this instance
396 /// is a sub container.
398 IWindsorContainer Parent { get; set; }
401 /// Resolve all valid components that match this type.
403 /// <typeparam name="T">The service type</typeparam>
407 /// Resolve all valid components that mathc this service
408 /// <param name="service">the service to match</param>
410 Array
ResolveAll(Type service
);
413 /// Resolve all valid components that mathc this service
414 /// <param name="service">the service to match</param>
415 /// <param name="arguments">Arguments to resolve the service</param>
417 Array
ResolveAll(Type service
, IDictionary arguments
);
420 /// Resolve all valid components that mathc this service
421 /// <param name="service">the service to match</param>
422 /// <param name="argumentsAsAnonymousType">Arguments to resolve the service</param>
424 Array
ResolveAll(Type service
, object argumentsAsAnonymousType
);
427 /// Resolve all valid components that match this type.
428 /// <typeparam name="T">The service type</typeparam>
429 /// <param name="arguments">Arguments to resolve the service</param>
431 T
[] ResolveAll
<T
>(IDictionary arguments
);
434 /// Resolve all valid components that match this type.
435 /// <typeparam name="T">The service type</typeparam>
436 /// <param name="argumentsAsAnonymousType">Arguments to resolve the service</param>
438 T
[] ResolveAll
<T
>(object argumentsAsAnonymousType
);