Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / InversionOfControl / Castle.MicroKernel / IKernel.cs
blobf76f1f0d9cd0484f7d4fbaf9067d8ae2a34b836a
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.MicroKernel
17 using System;
18 using System.Collections;
19 using Castle.Core;
20 using Castle.MicroKernel.Registration;
22 /// <summary>
23 /// The <c>IKernel</c> interface exposes all the functionality
24 /// the MicroKernel implements.
25 /// </summary>
26 /// <remarks>
27 /// It allows you to register components and
28 /// request them by the key or the service they implemented.
29 /// It also allow you to register facilities and subsystem, thus
30 /// augmenting the functionality exposed by the kernel alone to fits
31 /// your needs.
32 /// <seealso cref="IFacility"/>
33 /// <seealso cref="ISubSystem"/>
34 /// </remarks>
35 public interface IKernel : IServiceProviderEx, IKernelEvents, IDisposable
37 /// <summary>
38 /// Adds a concrete class as a component
39 /// </summary>
40 /// <param name="key"></param>
41 /// <param name="classType"></param>
42 void AddComponent(String key, Type classType);
44 /// <summary>
45 /// Adds a concrete class
46 /// as a component with the specified <paramref name="lifestyle"/>.
47 /// </summary>
48 /// <param name="key">The key with which to index the component.</param>
49 /// <param name="classType">The <see cref="Type"/> of the component.</param>
50 /// <param name="lifestyle">The specified <see cref="LifestyleType"/> for the component.</param>
51 /// <remarks>
52 /// If you have indicated a lifestyle for the specified <paramref name="classType"/> using
53 /// attributes, this method will not overwrite that lifestyle. To do that, use the
54 /// <see cref="AddComponent(string,Type,LifestyleType,bool)"/> method.
55 /// </remarks>
56 /// <exception cref="ArgumentNullException">
57 /// Thrown if <paramref name="key"/>, or <paramref name="classType"/>
58 /// are <see langword="null"/>.
59 /// </exception>
60 /// <exception cref="ArgumentException">
61 /// Thrown if <paramref name="lifestyle"/> is <see cref="LifestyleType.Undefined"/>.
62 /// </exception>
63 void AddComponent(String key, Type classType, LifestyleType lifestyle);
65 /// <summary>
66 /// Adds a concrete class
67 /// as a component with the specified <paramref name="lifestyle"/>.
68 /// </summary>
69 /// <param name="key">The key with which to index the component.</param>
70 /// <param name="classType">The <see cref="Type"/> of the component.</param>
71 /// <param name="lifestyle">The specified <see cref="LifestyleType"/> for the component.</param>
72 /// <param name="overwriteLifestyle">
73 /// If <see langword="true"/>, then ignores all other configurations
74 /// for lifestyle and uses the value in the <paramref name="lifestyle"/> parameter.
75 /// </param>
76 /// <remarks>
77 /// If you have indicated a lifestyle for the specified <paramref name="classType"/> using
78 /// attributes, this method will not overwrite that lifestyle. To do that, use the
79 /// <see cref="AddComponent(string,Type,Type,LifestyleType,bool)"/> method.
80 /// </remarks>
81 /// <exception cref="ArgumentNullException">
82 /// Thrown if <paramref name="key"/> or <paramref name="classType"/>
83 /// are <see langword="null"/>.
84 /// </exception>
85 /// <exception cref="ArgumentException" />
86 /// Thrown if <paramref name="lifestyle"/> is <see cref="LifestyleType.Undefined"/>.
87 void AddComponent(String key, Type classType, LifestyleType lifestyle, bool overwriteLifestyle);
89 /// <summary>
90 /// Adds a concrete class and an interface
91 /// as a component
92 /// </summary>
93 /// <param name="key">The key with which to index the component.</param>
94 /// <param name="serviceType">The service <see cref="Type"/> that this component implements.</param>
95 /// <param name="classType">The <see cref="Type"/> of the component.</param>
96 void AddComponent(String key, Type serviceType, Type classType);
98 /// <summary>
99 /// Adds a concrete class and an interface
100 /// as a component with the specified <paramref name="lifestyle"/>.
101 /// </summary>
102 /// <param name="key">The key with which to index the component.</param>
103 /// <param name="serviceType">The service <see cref="Type"/> that this component implements.</param>
104 /// <param name="classType">The <see cref="Type"/> of the component.</param>
105 /// <param name="lifestyle">The specified <see cref="LifestyleType"/> for the component.</param>
106 /// <remarks>
107 /// If you have indicated a lifestyle for the specified <paramref name="classType"/> using
108 /// attributes, this method will not overwrite that lifestyle. To do that, use the
109 /// <see cref="AddComponent(string,Type,Type,LifestyleType,bool)"/> method.
110 /// </remarks>
111 /// <exception cref="ArgumentNullException">
112 /// Thrown if <paramref name="key"/>, <paramref name="serviceType"/>, or <paramref name="classType"/>
113 /// are <see langword="null"/>.
114 /// </exception>
115 /// <exception cref="ArgumentException">
116 /// Thrown if <paramref name="lifestyle"/> is <see cref="LifestyleType.Undefined"/>.
117 /// </exception>
118 void AddComponent(String key, Type serviceType, Type classType, LifestyleType lifestyle);
120 /// <summary>
121 /// Adds a concrete class and an interface
122 /// as a component with the specified <paramref name="lifestyle"/>.
123 /// </summary>
124 /// <param name="key">The key with which to index the component.</param>
125 /// <param name="serviceType">The service <see cref="Type"/> that this component implements.</param>
126 /// <param name="classType">The <see cref="Type"/> of the component.</param>
127 /// <param name="lifestyle">The specified <see cref="LifestyleType"/> for the component.</param>
128 /// <param name="overwriteLifestyle">
129 /// If <see langword="true"/>, then ignores all other configurations
130 /// for lifestyle and uses the value in the <paramref name="lifestyle"/> parameter.
131 /// </param>
132 /// <remarks>
133 /// If you have indicated a lifestyle for the specified <paramref name="classType"/> using
134 /// attributes, this method will not overwrite that lifestyle. To do that, use the
135 /// <see cref="AddComponent(string,Type,Type,LifestyleType,bool)"/> method.
136 /// </remarks>
137 /// <exception cref="ArgumentNullException">
138 /// Thrown if <paramref name="key"/>, <paramref name="serviceType"/>, or <paramref name="classType"/>
139 /// are <see langword="null"/>.
140 /// </exception>
141 /// <exception cref="ArgumentException">
142 /// Thrown if <paramref name="lifestyle"/> is <see cref="LifestyleType.Undefined"/>.
143 /// </exception>
144 void AddComponent(string key, Type serviceType, Type classType, LifestyleType lifestyle, bool overwriteLifestyle);
146 /// <summary>
147 /// Adds a concrete class as a component
148 /// </summary>
149 void AddComponent<T>();
151 /// <summary>
152 /// Adds a concrete class
153 /// as a component with the specified <paramref name="lifestyle"/>.
154 /// </summary>
155 /// <param name="lifestyle">The specified <see cref="LifestyleType"/> for the component.</param>
156 /// <remarks>
157 /// If you have indicated a lifestyle for the specified T using
158 /// attributes, this method will not overwrite that lifestyle. To do that, use the
159 /// <see cref="AddComponent(string,Type,LifestyleType,bool)"/> method.
160 /// </remarks>
161 /// <exception cref="ArgumentException">
162 /// Thrown if <paramref name="lifestyle"/> is <see cref="LifestyleType.Undefined"/>.
163 /// </exception>
164 void AddComponent<T>(LifestyleType lifestyle);
166 /// <summary>
167 /// Adds a concrete class
168 /// as a component with the specified <paramref name="lifestyle"/>.
169 /// </summary>
170 /// <param name="lifestyle">The specified <see cref="LifestyleType"/> for the component.</param>
171 /// <param name="overwriteLifestyle">
172 /// If <see langword="true"/>, then ignores all other configurations
173 /// for lifestyle and uses the value in the <paramref name="lifestyle"/> parameter.
174 /// </param>
175 /// <remarks>
176 /// If you have indicated a lifestyle for the specified T using
177 /// attributes, this method will not overwrite that lifestyle. To do that, use the
178 /// <see cref="AddComponent(string,Type,LifestyleType,bool)"/> method.
179 /// </remarks>
180 /// <exception cref="ArgumentException" />
181 /// Thrown if <paramref name="lifestyle"/> is <see cref="LifestyleType.Undefined"/>.
182 void AddComponent<T>(LifestyleType lifestyle, bool overwriteLifestyle);
184 /// <summary>
185 /// Adds a concrete class and an interface
186 /// as a component
187 /// </summary>
188 /// <param name="serviceType">The service <see cref="Type"/> that this component implements.</param>
189 void AddComponent<T>(Type serviceType);
191 /// <summary>
192 /// Adds a concrete class and an interface
193 /// as a component with the specified <paramref name="lifestyle"/>.
194 /// </summary>
195 /// <param name="serviceType">The service <see cref="Type"/> that this component implements.</param>
196 /// <param name="lifestyle">The specified <see cref="LifestyleType"/> for the component.</param>
197 /// <remarks>
198 /// If you have indicated a lifestyle for the specified T using
199 /// attributes, this method will not overwrite that lifestyle. To do that, use the
200 /// <see cref="AddComponent(string,Type,Type,LifestyleType,bool)"/> method.
201 /// </remarks>
202 /// <exception cref="ArgumentNullException">
203 /// are <see langword="null"/>.
204 /// </exception>
205 /// <exception cref="ArgumentException">
206 /// Thrown if <paramref name="lifestyle"/> is <see cref="LifestyleType.Undefined"/>.
207 /// </exception>
208 void AddComponent<T>(Type serviceType, LifestyleType lifestyle);
210 /// <summary>
211 /// Adds a concrete class and an interface
212 /// as a component with the specified <paramref name="lifestyle"/>.
213 /// </summary>
214 /// <param name="serviceType">The service <see cref="Type"/> that this component implements.</param>
215 /// <param name="lifestyle">The specified <see cref="LifestyleType"/> for the component.</param>
216 /// <param name="overwriteLifestyle">
217 /// If <see langword="true"/>, then ignores all other configurations
218 /// for lifestyle and uses the value in the <paramref name="lifestyle"/> parameter.
219 /// </param>
220 /// <remarks>
221 /// attributes, this method will not overwrite that lifestyle. To do that, use the
222 /// <see cref="AddComponent(string,Type,Type,LifestyleType,bool)"/> method.
223 /// </remarks>
224 /// <exception cref="ArgumentNullException">
225 /// are <see langword="null"/>.
226 /// </exception>
227 /// <exception cref="ArgumentException">
228 /// Thrown if <paramref name="lifestyle"/> is <see cref="LifestyleType.Undefined"/>.
229 /// </exception>
230 void AddComponent<T>(Type serviceType, LifestyleType lifestyle, bool overwriteLifestyle);
232 /// <summary>
233 /// Used mostly by facilities. Adds an instance
234 /// to be used as a component.
235 /// </summary>
236 /// <param name="instance"></param>
237 void AddComponentInstance<T>(object instance);
239 /// <summary>
240 /// Used mostly by facilities. Adds an instance
241 /// to be used as a component.
242 /// </summary>
243 /// <param name="serviceType"></param>
244 /// <param name="instance"></param>
245 void AddComponentInstance<T>(Type serviceType, object instance);
247 /// <summary>
248 /// Adds a concrete class as a component and specify the extended properties.
249 /// Used by facilities, mostly.
250 /// </summary>
251 /// <param name="key"></param>
252 /// <param name="classType"></param>
253 /// <param name="extendedProperties"></param>
254 void AddComponentWithExtendedProperties(String key, Type classType, IDictionary extendedProperties);
256 /// <summary>
257 /// Adds a concrete class and an interface
258 /// as a component and specify the extended properties.
259 /// Used by facilities, mostly.
260 /// </summary>
261 /// <param name="key"></param>
262 /// <param name="serviceType"></param>
263 /// <param name="classType"></param>
264 /// <param name="extendedProperties"></param>
265 void AddComponentWithExtendedProperties(String key, Type serviceType, Type classType, IDictionary extendedProperties);
267 /// <summary>
268 /// Adds a custom made <see cref="ComponentModel"/>.
269 /// Used by facilities.
270 /// </summary>
271 /// <param name="model"></param>
272 void AddCustomComponent(ComponentModel model);
274 /// <summary>
275 /// Used mostly by facilities. Adds an instance
276 /// to be used as a component.
277 /// </summary>
278 /// <param name="key"></param>
279 /// <param name="instance"></param>
280 void AddComponentInstance(String key, object instance);
282 /// <summary>
283 /// Used mostly by facilities. Adds an instance
284 /// to be used as a component.
285 /// </summary>
286 /// <param name="key"></param>
287 /// <param name="serviceType"></param>
288 /// <param name="instance"></param>
289 void AddComponentInstance(String key, Type serviceType, object instance);
291 /// <summary>
292 /// Used mostly by facilities. Adds an instance
293 /// to be used as a component.
294 /// </summary>
295 /// <param name="key"></param>
296 /// <param name="serviceType"></param>
297 /// <param name="instance"></param>
298 /// <param name="classType"></param>
299 void AddComponentInstance(string key, Type serviceType, Type classType, object instance);
301 /// <summary>
302 /// Registers the components described by the <see cref="ComponentRegistration{S}"/>s
303 /// with the <see cref="IKernel"/>.
304 /// <param name="registrations">The component registrations.</param>
305 /// <returns>The kernel.</returns>
306 /// </summary>
307 IKernel Register(params IRegistration[] registrations);
309 /// <summary>
310 /// Returns true if the specified component was
311 /// found and could be removed (i.e. no other component depends on it)
312 /// </summary>
313 /// <param name="key">The component's key</param>
314 /// <returns></returns>
315 bool RemoveComponent(String key);
317 /// <summary>
318 /// Returns true if the specified key was registered
319 /// </summary>
320 /// <param name="key"></param>
321 /// <returns></returns>
322 bool HasComponent(String key);
324 /// <summary>
325 /// Returns true if the specified service was registered
326 /// </summary>
327 /// <param name="service"></param>
328 /// <returns></returns>
329 bool HasComponent(Type service);
331 /// <summary>
332 /// Returns the component instance by the key
333 /// </summary>
334 object this[String key] { get; }
336 /// <summary>
337 /// Returns the component instance by the service type
338 /// </summary>
339 object this[Type service] { get; }
341 /// <summary>
342 /// Returns the component instance by the service type
343 /// </summary>
344 object Resolve(Type service);
346 /// <summary>
347 /// Returns all the valid component instances by
348 /// the service type
349 /// </summary>
350 /// <param name="service">The service type</param>
351 /// <param name="arguments">Arguments to resolve the services</param>
352 Array ResolveAll(Type service, IDictionary arguments);
354 /// <summary>
355 /// Returns all the valid component instances by
356 /// the service type
357 /// </summary>
358 /// <param name="service">The service type</param>
359 /// <param name="argumentsAsAnonymousType">Arguments to resolve the services</param>
360 Array ResolveAll(Type service, object argumentsAsAnonymousType);
362 /// <summary>
363 /// Returns the component instance by the service type
364 /// using dynamic arguments
365 /// </summary>
366 /// <param name="service"></param>
367 /// <param name="arguments"></param>
368 /// <returns></returns>
369 object Resolve(Type service, IDictionary arguments);
371 /// <summary>
372 /// Returns the component instance by the component key
373 /// using dynamic arguments
374 /// </summary>
375 /// <param name="key"></param>
376 /// <param name="arguments"></param>
377 /// <returns></returns>
378 object Resolve(String key, IDictionary arguments);
380 /// <summary>
381 /// Returns the component instance by the service type
382 /// using dynamic arguments
383 /// </summary>
384 /// <param name="service">Service to resolve</param>
385 /// <param name="argumentsAsAnonymousType">Arguments to resolve the services</param>
386 /// <returns></returns>
387 object Resolve(Type service, object argumentsAsAnonymousType);
389 /// <summary>
390 /// Returns the component instance by the component key
391 /// using dynamic arguments
392 /// </summary>
393 /// <param name="key">Key to resolve</param>
394 /// <param name="argumentsAsAnonymousType">Arguments to resolve the services</param>
395 /// <returns></returns>
396 object Resolve(String key, object argumentsAsAnonymousType);
398 /// <summary>
399 /// Returns a component instance by the key
400 /// </summary>
401 /// <param name="key"></param>
402 /// <param name="service"></param>
403 /// <returns></returns>
404 object Resolve(String key, Type service);
406 /// <summary>
407 /// Returns the component instance by the service type
408 /// using dynamic arguments
409 /// </summary>
410 /// <param name="arguments"></param>
411 /// <returns></returns>
412 T Resolve<T>(IDictionary arguments);
414 /// <summary>
415 /// Returns the component instance by the service type
416 /// using dynamic arguments
417 /// </summary>
418 /// <param name="argumentsAsAnonymousType">Arguments to resolve the services</param>
419 /// <returns></returns>
420 T Resolve<T>(object argumentsAsAnonymousType);
422 /// <summary>
423 /// Returns the component instance by the component key
424 /// </summary>
425 /// <returns></returns>
426 T Resolve<T>();
428 /// <summary>
429 /// Returns component instances that implement TService
430 /// </summary>
431 /// <typeparam name="TService"></typeparam>
432 /// <returns></returns>
433 TService[] ResolveServices<TService>();
435 /// <summary>
436 /// Returns a component instance by the key
437 /// </summary>
438 /// <param name="key"></param>
439 /// <param name="service"></param>
440 /// <param name="arguments"></param>
441 /// <returns></returns>
442 object Resolve(String key, Type service, IDictionary arguments);
444 /// <summary>
445 /// Associates objects with a component handler,
446 /// allowing it to use the specified dictionary
447 /// when resolving dependencies
448 /// </summary>
449 /// <param name="service"></param>
450 /// <param name="dependencies"></param>
451 void RegisterCustomDependencies(Type service, IDictionary dependencies);
453 /// <summary>
454 /// Associates objects with a component handler,
455 /// allowing it to use the specified dictionary
456 /// when resolving dependencies
457 /// </summary>
458 /// <param name="service"></param>
459 /// <param name="dependenciesAsAnonymousType"></param>
460 void RegisterCustomDependencies(Type service, object dependenciesAsAnonymousType);
462 /// <summary>
463 /// Associates objects with a component handler,
464 /// allowing it to use the specified dictionary
465 /// when resolving dependencies
466 /// </summary>
467 /// <param name="key"></param>
468 /// <param name="dependencies"></param>
469 void RegisterCustomDependencies(String key, IDictionary dependencies);
471 /// <summary>
472 /// Associates objects with a component handler,
473 /// allowing it to use the specified dictionary
474 /// when resolving dependencies
475 /// </summary>
476 /// <param name="key"></param>
477 /// <param name="dependenciesAsAnonymousType"></param>
478 void RegisterCustomDependencies(String key, object dependenciesAsAnonymousType);
480 /// <summary>
481 /// Releases a component instance. This allows
482 /// the kernel to execute the proper decomission
483 /// lifecycles on the component instance.
484 /// </summary>
485 /// <param name="instance"></param>
486 void ReleaseComponent(object instance);
488 /// <summary>
489 /// Constructs an implementation of <see cref="IComponentActivator"/>
490 /// for the given <see cref="ComponentModel"/>
491 /// </summary>
492 /// <param name="model"></param>
493 /// <returns></returns>
494 IComponentActivator CreateComponentActivator(ComponentModel model);
496 /// <summary>
497 /// Returns the implementation of <see cref="IComponentModelBuilder"/>
498 /// </summary>
499 IComponentModelBuilder ComponentModelBuilder { get; }
501 /// <summary>
502 /// Returns the implementation of <see cref="IHandlerFactory"/>
503 /// </summary>
504 IHandlerFactory HandlerFactory { get; }
506 /// <summary>
507 /// Gets or sets the implementation of <see cref="IConfigurationStore"/>
508 /// </summary>
509 IConfigurationStore ConfigurationStore { get; set; }
511 /// <summary>
512 /// Returns the <see cref="IHandler"/>
513 /// for the specified component key.
514 /// </summary>
515 /// <param name="key"></param>
516 /// <returns></returns>
517 IHandler GetHandler(String key);
519 /// <summary>
520 /// Returns the <see cref="IHandler"/>
521 /// for the specified service.
522 /// </summary>
523 /// <param name="service"></param>
524 /// <returns></returns>
525 IHandler GetHandler(Type service);
527 /// <summary>
528 /// Return handlers for components that
529 /// implements the specified service.
530 /// </summary>
531 /// <param name="service"></param>
532 /// <returns></returns>
533 IHandler[] GetHandlers(Type service);
535 /// <summary>
536 /// Return handlers for components that
537 /// implements the specified service.
538 /// The check is made using IsAssignableFrom
539 /// </summary>
540 /// <param name="service"></param>
541 /// <returns></returns>
542 IHandler[] GetAssignableHandlers(Type service);
544 /// <summary>
545 /// Gets or sets the implementation for <see cref="IReleasePolicy"/>
546 /// </summary>
547 IReleasePolicy ReleasePolicy { get; set; }
549 /// <summary>
550 /// Returns the implementation for <see cref="IDependencyResolver"/>
551 /// </summary>
552 IDependencyResolver Resolver { get; }
554 /// <summary>
555 /// Adds a <see cref="IFacility"/> to the kernel.
556 /// </summary>
557 /// <param name="key"></param>
558 /// <param name="facility"></param>
559 void AddFacility(String key, IFacility facility);
561 /// <summary>
562 /// Returns the facilities registered on the kernel.
563 /// </summary>
564 /// <returns></returns>
565 IFacility[] GetFacilities();
567 /// <summary>
568 /// Adds (or replaces) an <see cref="ISubSystem"/>
569 /// </summary>
570 /// <param name="key"></param>
571 /// <param name="subsystem"></param>
572 void AddSubSystem(String key, ISubSystem subsystem);
574 /// <summary>
575 /// Returns an implementation of <see cref="ISubSystem"/>
576 /// for the specified key.
577 /// <seealso cref="SubSystemConstants"/>
578 /// </summary>
579 /// <param name="key"></param>
580 /// <returns></returns>
581 ISubSystem GetSubSystem(String key);
583 /// <summary>
584 /// Gets or sets the implementation of <see cref="IProxyFactory"/>
585 /// allowing different strategies for proxy creation.
586 /// </summary>
587 IProxyFactory ProxyFactory { get; set; }
589 /// <summary>
590 /// Returns the parent kernel
591 /// </summary>
592 IKernel Parent { get; set; }
594 /// <summary>
595 /// Support for kernel hierarchy
596 /// </summary>
597 /// <param name="kernel"></param>
598 void AddChildKernel(IKernel kernel);
600 /// <summary>
601 /// Remove child kernel
602 /// </summary>
603 /// <param name="kernel"></param>
604 void RemoveChildKernel(IKernel kernel);
606 /// <summary>
607 /// Graph of components and iteractions.
608 /// </summary>
609 GraphNode[] GraphNodes { get; }
611 /// <summary>
612 /// Raise the hanlder registered event, required so
613 /// dependant handlers will be notified about their dependant moving
614 /// to valid state.
615 /// </summary>
616 /// <param name="handler"></param>
617 void RaiseHandlerRegistered(IHandler handler);