Fixing an issue with output parameters that are of type IntPtr
[castle.git] / MonoRail / Castle.MonoRail.Framework / Services / DefaultServiceInitializer.cs
blobd70bceefa51af146dd0512aca61ba0127e391c05
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.MonoRail.Framework.Services
17 using System;
18 using Core;
20 /// <summary>
21 ///
22 /// </summary>
23 public class DefaultServiceInitializer : IServiceInitializer
25 /// <summary>
26 /// Initializes the specified service instance.
27 /// </summary>
28 /// <param name="serviceInstance">The service instance.</param>
29 /// <param name="engineContext">The engine context.</param>
30 public void Initialize(object serviceInstance, IEngineContext engineContext)
32 IController controller = engineContext.CurrentController;
33 IControllerContext controllerCtx = engineContext.CurrentControllerContext;
35 IContextAware ctxAware = serviceInstance as IContextAware;
37 if (ctxAware != null)
39 ctxAware.SetContext(engineContext);
42 IControllerAware aware = serviceInstance as IControllerAware;
44 if (aware != null)
46 aware.SetController(controller, controllerCtx);
49 Initialize(serviceInstance, engineContext.Services);
52 /// <summary>
53 /// Initializes the specified service instance.
54 /// </summary>
55 /// <param name="serviceInstance">The service instance.</param>
56 /// <param name="container">The container.</param>
57 public void Initialize(object serviceInstance, IMonoRailServices container)
59 IServiceEnabledComponent serviceEnabled = serviceInstance as IServiceEnabledComponent;
61 if (serviceEnabled != null)
63 serviceEnabled.Service(container);
66 IMRServiceEnabled mrServiceEnabled = serviceInstance as IMRServiceEnabled;
68 if (mrServiceEnabled != null)
70 mrServiceEnabled.Service(container);
73 IInitializable initializable = serviceInstance as IInitializable;
75 if (initializable != null)
77 initializable.Initialize();