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
;
23 /// The <c>IWindsorContainer</c> interface exposes all the
24 /// functionality the Windsor implements.
26 public interface IWindsorContainer
: IServiceProviderEx
, IDisposable
29 /// Gets the container's name
32 /// Only useful when child containers are being used
34 /// <value>The container's name.</value>
38 /// Registers a facility within the kernel.
40 /// <param name="key">The key by which the <see cref="IFacility"/> gets indexed.</param>
41 /// <param name="facility">The <see cref="IFacility"/> to add to the container.</param>
42 void AddFacility(String key
, IFacility facility
);
45 /// Adds a component to be managed by the container
47 /// <param name="key">The key by which the component gets indexed.</param>
48 /// <param name="classType">The <see cref="Type"/> to manage.</param>
49 void AddComponent(String key
, Type classType
);
52 /// Adds a component to be managed by the container
54 /// <param name="key">The key by which the component gets indexed.</param>
55 /// <param name="serviceType">The service <see cref="Type"/> that the component implements.</param>
56 /// <param name="classType">The <see cref="Type"/> to manage.</param>
57 void AddComponent(String key
, Type serviceType
, Type classType
);
60 /// Adds a component to be managed by the container
62 /// <param name="key">The key by which the component gets indexed.</param>
63 /// <param name="classType">The <see cref="Type"/> to manage.</param>
64 /// <param name="lifestyle">The <see cref="LifestyleType"/> with which to manage the component.</param>
65 void AddComponentWithLifestyle(String key
, Type classType
, LifestyleType lifestyle
);
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 /// <param name="lifestyle">The <see cref="LifestyleType"/> with which to manage the component.</param>
74 void AddComponentWithLifestyle(String key
, Type serviceType
, Type classType
, LifestyleType lifestyle
);
77 /// Adds a concrete class as a component and specify the extended properties.
78 /// Used by facilities, mostly.
80 /// <param name="key"></param>
81 /// <param name="classType"></param>
82 /// <param name="extendedProperties"></param>
83 void AddComponentWithProperties(String key
, Type classType
, IDictionary extendedProperties
);
86 /// Adds a concrete class and an interface
87 /// as a component and specify the extended properties.
88 /// Used by facilities, mostly.
90 /// <param name="key"></param>
91 /// <param name="serviceType"></param>
92 /// <param name="classType"></param>
93 /// <param name="extendedProperties"></param>
94 void AddComponentWithProperties(String key
, Type serviceType
, Type classType
, IDictionary extendedProperties
);
97 /// Adds a component to be managed by the container.
98 /// The key to obtain the component will be the FullName of the type.
100 /// <typeparam name="T">The <see cref="Type"/> to manage.</typeparam>
101 void AddComponent
<T
>();
104 /// Adds a component to be managed by the container
106 /// <typeparam name="T">The <see cref="Type"/> to manage.</typeparam>
107 /// <param name="key">The key by which the component gets indexed.</param>
108 void AddComponent
<T
>(String key
);
111 /// Adds a component to be managed by the container.
112 /// The key to obtain the component will be the FullName of the type.
114 /// <typeparam name="T">The <see cref="Type"/> to manage.</typeparam>
115 /// <param name="lifestyle">The <see cref="LifestyleType"/> with which to manage the component.</param>
116 void AddComponentWithLifestyle
<T
>(LifestyleType lifestyle
);
119 /// Adds a component to be managed by the container
121 /// <typeparam name="T">The <see cref="Type"/> to manage.</typeparam>
122 /// <param name="key">The key by which the component gets indexed.</param>
123 /// <param name="lifestyle">The <see cref="LifestyleType"/> with which to manage the component.</param>
124 void AddComponentWithLifestyle
<T
>(String key
, LifestyleType lifestyle
);
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="I">The service <see cref="Type"/> that the component implements.</typeparam>
131 /// <typeparam name="T">The <see cref="Type"/> to manage.</typeparam>
132 void AddComponent
<I
, T
>() where T
: class;
135 /// Adds a component to be managed by the container
137 /// <typeparam name="I">The service <see cref="Type"/> that the component implements.</typeparam>
138 /// <typeparam name="T">The <see cref="Type"/> to manage.</typeparam>
139 /// <param name="key">The key by which the component gets indexed.</param>
140 void AddComponent
<I
, T
>(String key
) where T
: class;
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 /// <param name="lifestyle">The <see cref="LifestyleType"/> with which to manage the component.</param>
149 void AddComponentWithLifestyle
<I
, T
>(LifestyleType lifestyle
) where T
: class;
152 /// Adds a component to be managed by the container
154 /// <typeparam name="I">The service <see cref="Type"/> that the component implements.</typeparam>
155 /// <typeparam name="T">The <see cref="Type"/> to manage.</typeparam>
156 /// <param name="key">The key by which the component gets indexed.</param>
157 /// <param name="lifestyle">The <see cref="LifestyleType"/> with which to manage the component.</param>
158 void AddComponentWithLifestyle
<I
, T
>(String key
, LifestyleType lifestyle
) where T
: class;
161 /// Adds a concrete class as a component and specify the extended properties.
162 /// Used by facilities, mostly.
163 /// The key to obtain the component will be the FullName of the type.
165 /// <typeparam name="T"></typeparam>
166 /// <param name="extendedProperties"></param>
167 void AddComponentWithProperties
<T
>(IDictionary extendedProperties
);
170 /// Adds a concrete class as a component and specify the extended properties.
171 /// Used by facilities, mostly.
173 /// <typeparam name="T"></typeparam>
174 /// <param name="key"></param>
175 /// <param name="extendedProperties"></param>
176 void AddComponentWithProperties
<T
>(String key
, IDictionary extendedProperties
);
179 /// Adds a concrete class and an interface
180 /// as a component and specify the extended properties.
181 /// Used by facilities, mostly.
182 /// The key to obtain the component will be the FullName of the type.
184 /// <typeparam name="I"></typeparam>
185 /// <typeparam name="T"></typeparam>
186 /// <param name="extendedProperties"></param>
187 void AddComponentWithLifestyle
<I
, T
>(IDictionary extendedProperties
) where T
: class;
190 /// Adds a concrete class and an interface
191 /// as a component and specify the extended properties.
192 /// Used by facilities, mostly.
194 /// <typeparam name="I"></typeparam>
195 /// <typeparam name="T"></typeparam>
196 /// <param name="key"></param>
197 /// <param name="extendedProperties"></param>
198 void AddComponentWithLifestyle
<I
, T
>(String key
, IDictionary extendedProperties
) where T
: class;
201 /// Returns a component instance by the key
203 /// <param name="key"></param>
204 /// <returns></returns>
205 object Resolve(String key
);
208 /// Returns a component instance by the key
210 /// <param name="key"></param>
211 /// <param name="arguments"></param>
212 /// <returns></returns>
213 object Resolve(String key
, IDictionary arguments
);
216 /// Returns a component instance by the key
218 /// <param name="key"></param>
219 /// <param name="service"></param>
220 /// <returns></returns>
221 object Resolve(String key
, Type service
);
224 /// Returns a component instance by the service
226 /// <param name="service"></param>
227 /// <returns></returns>
228 object Resolve(Type service
);
231 /// Returns a component instance by the service
233 /// <param name="service"></param>
234 /// <param name="arguments"></param>
235 /// <returns></returns>
236 object Resolve(Type service
, IDictionary arguments
);
239 /// Releases a component instance
241 /// <param name="instance"></param>
242 void Release(object instance
);
245 /// Registers a subcontainer. The components exposed
246 /// by this container will be accessible from subcontainers.
248 /// <param name="childContainer"></param>
249 void AddChildContainer(IWindsorContainer childContainer
);
252 /// Remove a child container
254 /// <param name="childContainer"></param>
255 void RemoveChildContainer(IWindsorContainer childContainer
);
258 /// Shortcut to <see cref="Resolve(string)"/>
260 object this [String key
] { get; }
263 /// Shortcut to <see cref="Resolve(Type)"/>
265 object this [Type service
] { get; }
268 /// Gets a child container instance by name.
270 /// <param name="name">The container's name.</param>
271 /// <returns>The child container instance or null</returns>
272 IWindsorContainer
GetChildContainer(string name
);
275 /// Returns a component instance by the service
277 /// <typeparam name="T">Service type</typeparam>
278 /// <returns>The component instance</returns>
282 /// Returns a component instance by the service
284 /// <typeparam name="T">Service type</typeparam>
285 /// <param name="arguments"></param>
286 /// <returns>The component instance</returns>
287 T Resolve
<T
>(IDictionary arguments
);
290 /// Returns a component instance by the key
292 /// <param name="key">Component's key</param>
293 /// <typeparam name="T">Service type</typeparam>
294 /// <returns>The Component instance</returns>
295 T Resolve
<T
>(String key
);
298 /// Returns a component instance by the key
300 /// <typeparam name="T">Service type</typeparam>
301 /// <param name="key">Component's key</param>
302 /// <param name="arguments"></param>
303 /// <returns>The Component instance</returns>
304 T Resolve
<T
>(String key
, IDictionary arguments
);
308 /// Returns a component instance by the key
310 /// <param name="key"></param>
311 /// <param name="service"></param>
312 /// <param name="arguments"></param>
313 /// <returns></returns>
314 object Resolve(String key
, Type service
, IDictionary arguments
);
317 /// Returns the inner instance of the MicroKernel
319 IKernel Kernel { get; }
322 /// Gets or sets the parent container if this instance
323 /// is a sub container.
325 IWindsorContainer Parent { get; set; }