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
.MonoRail
.Framework
.Services
23 public class DefaultServiceInitializer
: IServiceInitializer
26 /// Initializes the specified service instance.
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
;
39 ctxAware
.SetContext(engineContext
);
42 IControllerAware aware
= serviceInstance
as IControllerAware
;
46 aware
.SetController(controller
, controllerCtx
);
49 Initialize(serviceInstance
, engineContext
.Services
);
53 /// Initializes the specified service instance.
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();