1 // Copyright 2004-2008 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
22 /// Possible states for a IHandler instance
24 public enum HandlerState
27 /// The component can be requested
31 /// The component can not be requested
32 /// as it still depending on a external
33 /// dependency not yet available
41 /// <param name="source"></param>
42 /// <param name="args"></param>
43 public delegate void HandlerStateDelegate(object source
, EventArgs args
);
46 /// Contract for the IHandler, which manages an
47 /// component state and coordinates its creation
48 /// and destruction (dispatching to activators, lifestyle managers)
50 public interface IHandler
: ISubDependencyResolver
53 /// Initializes the handler with a reference to the
56 /// <param name="kernel"></param>
57 void Init(IKernel kernel
);
60 /// Implementors should return a valid instance
61 /// for the component the handler is responsible.
62 /// It should throw an exception in the case the component
63 /// can't be created for some reason
65 /// <returns></returns>
66 object Resolve(CreationContext context
);
69 /// Implementors should dispose the component instance
71 /// <param name="instance"></param>
72 void Release(object instance
);
75 /// Gets the state of the handler
77 HandlerState CurrentState { get; }
80 /// Gets the model of the component being
81 /// managed by this handler.
83 ComponentModel ComponentModel { get; }
86 /// TODO: Document this
88 event HandlerStateDelegate OnHandlerStateChanged
;
91 /// Dictionary of String/object used to
92 /// associate data with a component dependency.
93 /// For example, if you component SmtpServer depends on
94 /// host and port, you can add those to this
95 /// dictionary and the handler will be able to use them.
98 /// TODO: Document this
100 void AddCustomDependencyValue(string key
, object value);
103 /// TODO: Document this
105 /// <param name="key"></param>
106 void RemoveCustomDependencyValue(string key
);
109 /// TODO: Document this
111 /// <param name="key"></param>
112 /// <returns></returns>
113 bool HasCustomParameter(string key
);