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
: 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 /// Returns a component instance by the key
99 /// <param name="key"></param>
100 /// <returns></returns>
101 object Resolve(String key
);
104 /// Returns a component instance by the key
106 /// <param name="key"></param>
107 /// <param name="arguments"></param>
108 /// <returns></returns>
109 object Resolve(String key
, IDictionary arguments
);
114 /// Returns a component instance by the key
116 /// <param name="key"></param>
117 /// <param name="service"></param>
118 /// <returns></returns>
119 object Resolve(String key
, Type service
);
124 /// Returns a component instance by the service
126 /// <param name="service"></param>
127 /// <returns></returns>
128 object Resolve(Type service
);
131 /// Returns a component instance by the service
133 /// <param name="service"></param>
134 /// <param name="arguments"></param>
135 /// <returns></returns>
136 object Resolve(Type service
, IDictionary arguments
);
139 /// Releases a component instance
141 /// <param name="instance"></param>
142 void Release(object instance
);
145 /// Registers a subcontainer. The components exposed
146 /// by this container will be accessible from subcontainers.
148 /// <param name="childContainer"></param>
149 void AddChildContainer(IWindsorContainer childContainer
);
152 /// Remove a child container
154 /// <param name="childContainer"></param>
155 void RemoveChildContainer(IWindsorContainer childContainer
);
158 /// Shortcut to <see cref="Resolve(string)"/>
160 object this [String key
] { get; }
163 /// Shortcut to <see cref="Resolve(Type)"/>
165 object this [Type service
] { get; }
168 /// Gets a child container instance by name.
170 /// <param name="name">The container's name.</param>
171 /// <returns>The child container instance or null</returns>
172 IWindsorContainer
GetChildContainer(string name
);
177 /// Returns a component instance by the service
179 /// <typeparam name="T">Service type</typeparam>
180 /// <returns>The component instance</returns>
184 /// Returns a component instance by the service
186 /// <typeparam name="T">Service type</typeparam>
187 /// <param name="arguments"></param>
188 /// <returns>The component instance</returns>
189 T Resolve
<T
>(IDictionary arguments
);
192 /// Returns a component instance by the key
194 /// <param name="key">Component's key</param>
195 /// <typeparam name="T">Service type</typeparam>
196 /// <returns>The Component instance</returns>
197 T Resolve
<T
>(String key
);
200 /// Returns a component instance by the key
202 /// <typeparam name="T">Service type</typeparam>
203 /// <param name="key">Component's key</param>
204 /// <param name="arguments"></param>
205 /// <returns>The Component instance</returns>
206 T Resolve
<T
>(String key
, IDictionary arguments
);
210 /// Returns a component instance by the key
212 /// <param name="key"></param>
213 /// <param name="service"></param>
214 /// <param name="arguments"></param>
215 /// <returns></returns>
216 object Resolve(String key
, Type service
, IDictionary arguments
);
221 /// Returns the inner instance of the MicroKernel
223 IKernel Kernel { get; }
226 /// Gets or sets the parent container if this instance
227 /// is a sub container.
229 IWindsorContainer Parent { get; set; }