Castle[.net2.0] tips-1: Windsor注册ViewComponent的名称区分大小写
在Monorail集成了Windsor后,所有Controller和ViewComponent都要向WindsorContainer注册.
AddComponent("Menu",typeof(MenuComponent));
调用时 [NVelocity]
<div id="menu">#component(MenuComponent)</div>
错位现象:
第一次我在注册时使用的是
AddComponent("menu", typeof(MenuComponent));
按上边方法调用报错: 找不到MenuComponent,提示我可能没向WindsorContainer注册.
Castle.MonoRail.Framework.RailsException: ViewComponent 'menuComponent' could not be found. Was it registered? If you have enabled Windsor Integration, then it's likely that you have forgot to register the view component as a Windsor component. If you are sure you did it, then make sure the name used is the component id or the key passed to ViewComponentDetailsAttribute
在 Castle.MonoRail.Framework.Services.DefaultViewComponentRegistry.GetViewComponent(String name)
在 Castle.MonoRail.Framework.Services.AbstractViewComponentFactory.ResolveType(String name)
在 Castle.MonoRail.WindsorExtension.WindsorViewComponentFactory.Create(String name)
在 Castle.MonoRail.Framework.Views.NVelocity.CustomDirectives.AbstractComponentDirective.Render(IInternalContextAdapter context, TextWriter writer, INode node)
在 NVelocity.Runtime.Parser.Node.ASTDirective.Render(IInternalContextAdapter context, TextWriter writer)
在 NVelocity.Runtime.Parser.Node.SimpleNode.Render(IInternalContextAdapter context, TextWriter writer)
在 NVelocity.Template.Merge(IContext context, TextWriter writer)
在 Castle.MonoRail.Framework.Views.NVelocity.NVelocityViewEngine.RenderLayout(String layoutName, String contents, IContext ctx, IRailsEngineContext context, TextWriter output)
在 Castle.MonoRail.Framework.Services.DefaultViewComponentRegistry.GetViewComponent(String name)
在 Castle.MonoRail.Framework.Services.AbstractViewComponentFactory.ResolveType(String name)
在 Castle.MonoRail.WindsorExtension.WindsorViewComponentFactory.Create(String name)
在 Castle.MonoRail.Framework.Views.NVelocity.CustomDirectives.AbstractComponentDirective.Render(IInternalContextAdapter context, TextWriter writer, INode node)
在 NVelocity.Runtime.Parser.Node.ASTDirective.Render(IInternalContextAdapter context, TextWriter writer)
在 NVelocity.Runtime.Parser.Node.SimpleNode.Render(IInternalContextAdapter context, TextWriter writer)
在 NVelocity.Template.Merge(IContext context, TextWriter writer)
在 Castle.MonoRail.Framework.Views.NVelocity.NVelocityViewEngine.RenderLayout(String layoutName, String contents, IContext ctx, IRailsEngineContext context, TextWriter output)
后改为这样调用
<div id="menu">#component(menuComponent)</div>
一切正常了.
注意: NVelocity调用component时使用的不是 component类的类名 而是 Component类在 WindsorContainer中的注册名,此注册名严格区分大小写,在NVelocity中引用时请万分注意.希望高手开发一个NVelocity的只能提示,或可减少此类问题的困扰.