Added Changes.txt
[castle.git] / MonoRail / Castle.MonoRail.WindsorExtension / WindsorControllerFactory.cs
blob21dd7f594dcdcc18e1544185947b2c95b6e3ea10
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.WindsorExtension
17 using System;
19 using Castle.Windsor;
20 using Castle.MicroKernel;
22 using Castle.MonoRail.Framework;
24 /// <summary>
25 /// Custom implementation of <see cref="IControllerFactory"/>
26 /// that uses the WindsorContainer to obtain the
27 /// controller instances.
28 /// </summary>
29 public class WindsorControllerFactory : IControllerFactory
31 public Controller CreateController(UrlInfo urlInfo)
33 IWindsorContainer container = ContainerAccessorUtil.ObtainContainer();
35 IControllerTree tree;
37 try
39 tree = (IControllerTree) container["rails.controllertree"];
41 catch(ComponentNotFoundException)
43 throw new RailsException("ControllerTree not found. Check whether RailsFacility is properly configured/registered");
46 Type implType = tree.GetController(urlInfo.Area, urlInfo.Controller);
48 if (implType == null)
50 throw new ControllerNotFoundException(urlInfo);
53 return (Controller) container[implType];
56 public void Release(Controller controller)
58 ContainerAccessorUtil.ObtainContainer().Release(controller);