Added non-generic registration interface to IKernel and IWindsor to accommodate dynam...
[castle.git] / MonoRail / Castle.MonoRail.Framework / Extensions / ExtensionManager.cs
blobb833c3041c62ba7c41e0d9226220f18979943d72
1 // Copyright 2004-2007 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.MonoRail.Framework
17 using System;
18 using System.Collections.Generic;
19 using System.ComponentModel;
21 /// <summary>
22 ///
23 /// </summary>
24 /// <param name="context"></param>
25 public delegate void ExtensionHandler(IEngineContext context);
27 /// <summary>
28 /// MonoRail's extension manager.
29 /// It fires events related to MonoRail that can be used to add additional behaviour.
30 /// </summary>
31 public class ExtensionManager : MarshalByRefObject
33 private static readonly object ActionExceptionEvent = new object();
34 private static readonly object UnhandledExceptionEvent = new object();
35 private static readonly object AcquireSessionStateEvent = new object();
36 private static readonly object ReleaseSessionStateEvent = new object();
37 private static readonly object PreProcessControllerEvent = new object();
38 private static readonly object PostProcessControllerEvent = new object();
40 private readonly EventHandlerList events;
41 private readonly IMonoRailServices serviceProvider;
42 private readonly List<IMonoRailExtension> extensions = new List<IMonoRailExtension>();
44 /// <summary>
45 /// Initializes a new instance of the <see cref="ExtensionManager"/> class.
46 /// </summary>
47 /// <param name="serviceContainer">The service container.</param>
48 public ExtensionManager(IMonoRailServices serviceContainer)
50 events = new EventHandlerList();
51 serviceProvider = serviceContainer;
54 /// <summary>
55 /// Gets the service container.
56 /// </summary>
57 /// <value>The service container.</value>
58 public IMonoRailServices ServiceProvider
60 get { return serviceProvider; }
63 /// <summary>
64 /// Gets the extensions.
65 /// </summary>
66 /// <value>The extensions.</value>
67 public List<IMonoRailExtension> Extensions
69 get { return extensions; }
72 /// <summary>
73 /// Occurs when an action throws an exception.
74 /// </summary>
75 public event ExtensionHandler ActionException
77 add { events.AddHandler(ActionExceptionEvent, value); }
78 remove { events.RemoveHandler(ActionExceptionEvent, value); }
81 /// <summary>
82 /// Occurs when an unhandled exception is thrown.
83 /// </summary>
84 public event ExtensionHandler UnhandledException
86 add { events.AddHandler(UnhandledExceptionEvent, value); }
87 remove { events.RemoveHandler(UnhandledExceptionEvent, value); }
90 /// <summary>
91 /// Occurs when a session is adquired.
92 /// </summary>
93 public event ExtensionHandler AcquireSessionState
95 add { events.AddHandler(AcquireSessionStateEvent, value); }
96 remove { events.RemoveHandler(AcquireSessionStateEvent, value); }
99 /// <summary>
100 /// Occurs when a session is released.
101 /// </summary>
102 public event ExtensionHandler ReleaseSessionState
104 add { events.AddHandler(ReleaseSessionStateEvent, value); }
105 remove { events.RemoveHandler(ReleaseSessionStateEvent, value); }
108 /// <summary>
109 /// Occurs before processing controller.
110 /// </summary>
111 public event ExtensionHandler PreControllerProcess
113 add { events.AddHandler(PreProcessControllerEvent, value); }
114 remove { events.RemoveHandler(PreProcessControllerEvent, value); }
117 /// <summary>
118 /// Occurs after processing controller.
119 /// </summary>
120 public event ExtensionHandler PostControllerProcess
122 add { events.AddHandler(PostProcessControllerEvent, value); }
123 remove { events.RemoveHandler(PostProcessControllerEvent, value); }
126 internal void RaiseReleaseRequestState(IEngineContext context)
128 ExtensionHandler eventDelegate = (ExtensionHandler) events[ReleaseSessionStateEvent];
129 if (eventDelegate != null) eventDelegate(context);
132 internal void RaiseAcquireRequestState(IEngineContext context)
134 ExtensionHandler eventDelegate = (ExtensionHandler) events[AcquireSessionStateEvent];
135 if (eventDelegate != null) eventDelegate(context);
138 internal void RaiseUnhandledError(IEngineContext context)
140 ExtensionHandler eventDelegate = (ExtensionHandler) events[UnhandledExceptionEvent];
141 if (eventDelegate != null) eventDelegate(context);
144 internal void RaiseActionError(IEngineContext context)
146 ExtensionHandler eventDelegate = (ExtensionHandler) events[ActionExceptionEvent];
147 if (eventDelegate != null) eventDelegate(context);
150 internal void RaisePostProcessController(IEngineContext context)
152 ExtensionHandler eventDelegate = (ExtensionHandler) events[PostProcessControllerEvent];
153 if (eventDelegate != null) eventDelegate(context);
156 internal void RaisePreProcessController(IEngineContext context)
158 ExtensionHandler eventDelegate = (ExtensionHandler) events[PreProcessControllerEvent];
159 if (eventDelegate != null) eventDelegate(context);