1 // Copyright 2004-2007 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
AddComponentWithLifestyle(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
AddComponentWithLifestyle(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 AddComponentWithLifestyle
<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 AddComponentWithLifestyle
<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 AddComponentWithLifestyle
<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 AddComponentWithLifestyle
<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 AddComponentWithLifestyle
<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 AddComponentWithLifestyle
<I
, T
>(String key
, IDictionary extendedProperties
) where T
: class;
202 /// Adds a component to be registered in the container using a fluent interface.
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
>();
209 /// Returns a component instance by the key
211 /// <param name="key"></param>
212 /// <returns></returns>
213 object Resolve(String key
);
216 /// Returns a component instance by the key
218 /// <param name="key"></param>
219 /// <param name="arguments"></param>
220 /// <returns></returns>
221 object Resolve(String key
, IDictionary arguments
);
224 /// Returns a component instance by the key
226 /// <param name="key"></param>
227 /// <param name="service"></param>
228 /// <returns></returns>
229 object Resolve(String key
, Type service
);
232 /// Returns a component instance by the service
234 /// <param name="service"></param>
235 /// <returns></returns>
236 object Resolve(Type service
);
239 /// Returns a component instance by the service
241 /// <param name="service"></param>
242 /// <param name="arguments"></param>
243 /// <returns></returns>
244 object Resolve(Type service
, IDictionary arguments
);
247 /// Releases a component instance
249 /// <param name="instance"></param>
250 void Release(object instance
);
253 /// Registers a subcontainer. The components exposed
254 /// by this container will be accessible from subcontainers.
256 /// <param name="childContainer"></param>
257 void AddChildContainer(IWindsorContainer childContainer
);
260 /// Remove a child container
262 /// <param name="childContainer"></param>
263 void RemoveChildContainer(IWindsorContainer childContainer
);
266 /// Shortcut to <see cref="Resolve(string)"/>
268 object this [String key
] { get; }
271 /// Shortcut to <see cref="Resolve(Type)"/>
273 object this [Type service
] { get; }
276 /// Gets a child container instance by name.
278 /// <param name="name">The container's name.</param>
279 /// <returns>The child container instance or null</returns>
280 IWindsorContainer
GetChildContainer(string name
);
283 /// Returns a component instance by the service
285 /// <typeparam name="T">Service type</typeparam>
286 /// <returns>The component instance</returns>
290 /// Returns a component instance by the service
292 /// <typeparam name="T">Service type</typeparam>
293 /// <param name="arguments"></param>
294 /// <returns>The component instance</returns>
295 T Resolve
<T
>(IDictionary arguments
);
298 /// Returns a component instance by the key
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
);
306 /// Returns a component instance by the key
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
);
316 /// Returns a component instance by the key
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
);
325 /// Returns the inner instance of the MicroKernel
327 IKernel Kernel { get; }
330 /// Gets or sets the parent container if this instance
331 /// is a sub container.
333 IWindsorContainer Parent { get; set; }
336 /// Resolve all valid components that match this type.
338 /// <typeparam name="T">The service type</typeparam>
342 /// Resolve all valid components that mathc this service
343 /// <param name="service">the service to match</param>
345 Array
ResolveAll(Type service
);
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>
352 Array
ResolveAll(Type service
, IDictionary arguments
);
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>
359 T
[] ResolveAll
<T
>(IDictionary arguments
);