1 // Copyright 2004-2007 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
.WindsorExtension
20 using Castle
.MicroKernel
;
22 using Castle
.MonoRail
.Framework
;
25 /// Custom implementation of <see cref="IControllerFactory"/>
26 /// that uses the WindsorContainer to obtain the
27 /// controller instances.
29 public class WindsorControllerFactory
: IControllerFactory
31 public Controller
CreateController(UrlInfo urlInfo
)
33 IWindsorContainer container
= ContainerAccessorUtil
.ObtainContainer();
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
);
50 throw new ControllerNotFoundException(urlInfo
);
53 return (Controller
) container
[implType
];
56 public void Release(Controller controller
)
58 ContainerAccessorUtil
.ObtainContainer().Release(controller
);