- Implemented support for view component caching. Just use the attribute
[castle.git] / MonoRail / Castle.MonoRail.WindsorExtension / WindsorViewComponentFactory.cs
blobe2f9aadff8991889d12598c510eb7f894d6a00db
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;
18 using Castle.MonoRail.Framework;
19 using Castle.MonoRail.Framework.Services;
20 using Castle.Windsor;
22 public class WindsorViewComponentFactory : AbstractViewComponentFactory
24 private IViewEngine viewEngine;
26 public override IViewEngine ViewEngine
28 get { return viewEngine; }
29 set { viewEngine = value; }
32 public override ViewComponent Create(String name)
34 IWindsorContainer container = WindsorContainerAccessorUtil.ObtainContainer();
35 Type type = ResolveType(name);
36 if (container.Kernel.HasComponent(type))
38 return (ViewComponent) container[type];
40 return (ViewComponent) Activator.CreateInstance(type);
43 protected override IViewComponentRegistry GetViewComponentRegistry()
45 IWindsorContainer container = WindsorContainerAccessorUtil.ObtainContainer();
46 return (IViewComponentRegistry) container["rails.viewcomponentregistry"];