Initial version of MicroKernel/Windsor fluent interface for registration (IoC-99)
[castle.git] / InversionOfControl / Castle.Windsor / IWindsorContainer.cs
bloba6f46af212b07de198ad0406e140079d1c9e9396
1 // Copyright 2004-2007 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 AddComponentWithLifestyle(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 AddComponentWithLifestyle(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 AddComponentWithLifestyle<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 AddComponentWithLifestyle<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 AddComponentWithLifestyle<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 AddComponentWithLifestyle<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 AddComponentWithLifestyle<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 AddComponentWithLifestyle<I, T>(String key, IDictionary extendedProperties) where T : class;
201 /// <summary>
202 /// Adds a component to be registered in the container using a fluent interface.
203 /// </summary>
204 /// <typeparam name="S">The <see cref="Type"/> to manage.</typeparam>
205 /// <returns>The <see cref="ComponentRegistration{S,T}"/></returns>
206 ComponentRegistration<S,IWindsorContainer> AddComponentEx<S>();
208 /// <summary>
209 /// Returns a component instance by the key
210 /// </summary>
211 /// <param name="key"></param>
212 /// <returns></returns>
213 object Resolve(String key);
215 /// <summary>
216 /// Returns a component instance by the key
217 /// </summary>
218 /// <param name="key"></param>
219 /// <param name="arguments"></param>
220 /// <returns></returns>
221 object Resolve(String key, IDictionary arguments);
223 /// <summary>
224 /// Returns a component instance by the key
225 /// </summary>
226 /// <param name="key"></param>
227 /// <param name="service"></param>
228 /// <returns></returns>
229 object Resolve(String key, Type service);
231 /// <summary>
232 /// Returns a component instance by the service
233 /// </summary>
234 /// <param name="service"></param>
235 /// <returns></returns>
236 object Resolve(Type service);
238 /// <summary>
239 /// Returns a component instance by the service
240 /// </summary>
241 /// <param name="service"></param>
242 /// <param name="arguments"></param>
243 /// <returns></returns>
244 object Resolve(Type service, IDictionary arguments);
246 /// <summary>
247 /// Releases a component instance
248 /// </summary>
249 /// <param name="instance"></param>
250 void Release(object instance);
252 /// <summary>
253 /// Registers a subcontainer. The components exposed
254 /// by this container will be accessible from subcontainers.
255 /// </summary>
256 /// <param name="childContainer"></param>
257 void AddChildContainer(IWindsorContainer childContainer);
259 /// <summary>
260 /// Remove a child container
261 /// </summary>
262 /// <param name="childContainer"></param>
263 void RemoveChildContainer(IWindsorContainer childContainer);
265 /// <summary>
266 /// Shortcut to <see cref="Resolve(string)"/>
267 /// </summary>
268 object this [String key] { get; }
270 /// <summary>
271 /// Shortcut to <see cref="Resolve(Type)"/>
272 /// </summary>
273 object this [Type service] { get; }
275 /// <summary>
276 /// Gets a child container instance by name.
277 /// </summary>
278 /// <param name="name">The container's name.</param>
279 /// <returns>The child container instance or null</returns>
280 IWindsorContainer GetChildContainer(string name);
282 /// <summary>
283 /// Returns a component instance by the service
284 /// </summary>
285 /// <typeparam name="T">Service type</typeparam>
286 /// <returns>The component instance</returns>
287 T Resolve<T>();
289 /// <summary>
290 /// Returns a component instance by the service
291 /// </summary>
292 /// <typeparam name="T">Service type</typeparam>
293 /// <param name="arguments"></param>
294 /// <returns>The component instance</returns>
295 T Resolve<T>(IDictionary arguments);
297 /// <summary>
298 /// Returns a component instance by the key
299 /// </summary>
300 /// <param name="key">Component's key</param>
301 /// <typeparam name="T">Service type</typeparam>
302 /// <returns>The Component instance</returns>
303 T Resolve<T>(String key);
305 /// <summary>
306 /// Returns a component instance by the key
307 /// </summary>
308 /// <typeparam name="T">Service type</typeparam>
309 /// <param name="key">Component's key</param>
310 /// <param name="arguments"></param>
311 /// <returns>The Component instance</returns>
312 T Resolve<T>(String key, IDictionary arguments);
315 /// <summary>
316 /// Returns a component instance by the key
317 /// </summary>
318 /// <param name="key"></param>
319 /// <param name="service"></param>
320 /// <param name="arguments"></param>
321 /// <returns></returns>
322 object Resolve(String key, Type service, IDictionary arguments);
324 /// <summary>
325 /// Returns the inner instance of the MicroKernel
326 /// </summary>
327 IKernel Kernel { get; }
329 /// <summary>
330 /// Gets or sets the parent container if this instance
331 /// is a sub container.
332 /// </summary>
333 IWindsorContainer Parent { get; set; }
335 /// <summary>
336 /// Resolve all valid components that match this type.
337 /// </summary>
338 /// <typeparam name="T">The service type</typeparam>
339 T[] ResolveAll<T>();
341 /// <summary>
342 /// Resolve all valid components that mathc this service
343 /// <param name="service">the service to match</param>
344 /// </summary>
345 Array ResolveAll(Type service);
347 /// <summary>
348 /// Resolve all valid components that mathc this service
349 /// <param name="service">the service to match</param>
350 /// <param name="arguments">Arguments to resolve the service</param>
351 /// </summary>
352 Array ResolveAll(Type service, IDictionary arguments);
354 /// <summary>
355 /// Resolve all valid components that match this type.
356 /// <typeparam name="T">The service type</typeparam>
357 /// <param name="arguments">Arguments to resolve the service</param>
358 /// </summary>
359 T[] ResolveAll<T>(IDictionary arguments);