Support multiple service models for a component. WindsorServiceHostFactory will...
[castle.git] / MonoRail / Castle.MonoRail.WindsorExtension / WindsorViewComponentFactory.cs
blobb68fb6f39451fe1fa59e25763cd6c917031e974b
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.WindsorExtension
17 using System;
18 using Castle.MonoRail.Framework;
19 using Castle.MonoRail.Framework.Services;
20 using MicroKernel;
22 public class WindsorViewComponentFactory : AbstractViewComponentFactory
24 private readonly IViewComponentRegistry viewCompRegistry;
25 private readonly IKernel kernel;
26 private IViewEngine viewEngine;
28 public WindsorViewComponentFactory(IViewComponentRegistry viewCompRegistry, IKernel kernel)
30 this.viewCompRegistry = viewCompRegistry;
31 this.kernel = kernel;
34 public override IViewEngine ViewEngine
36 get { return viewEngine; }
37 set { viewEngine = value; }
40 public override ViewComponent Create(String name)
42 Type type = ResolveType(name);
44 if (kernel.HasComponent(type))
46 return (ViewComponent) kernel[type];
49 return (ViewComponent) Activator.CreateInstance(type);
52 protected override IViewComponentRegistry GetViewComponentRegistry()
54 return viewCompRegistry;