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
.MicroKernel
.Handlers
20 using System
.Collections
;
23 /// Summary description for DefaultHandler.
26 public class DefaultHandler
: AbstractHandler
29 /// Initializes a new instance of the <see cref="DefaultHandler"/> class.
31 /// <param name="model"></param>
32 public DefaultHandler(ComponentModel model
) : base(model
)
37 /// Returns an instance of the component this handler
38 /// is responsible for
40 /// <param name="context"></param>
41 /// <returns></returns>
42 public override object Resolve(CreationContext context
)
44 if (!context
.HasAdditionalParameters
)
46 AssertNotWaitingForDependency();
49 using (context
.ResolvingHandler(this))
51 return lifestyleManager
.Resolve(context
);
56 /// disposes the component instance (or recycle it)
58 /// <param name="instance"></param>
59 public override void Release(object instance
)
61 lifestyleManager
.Release(instance
);
64 protected void AssertNotWaitingForDependency()
66 if (CurrentState
== HandlerState
.WaitingDependency
)
68 String message
= String
.Format("Can't create component '{1}' " +
69 "as it has dependencies to be satisfied. {0}",
70 ObtainDependencyDetails(new ArrayList()), ComponentModel
.Name
);
72 throw new HandlerException(message
);