2011-06-16 61 views
3

我在我的C#web应用程序中使用单轨。由于我将它升级(.Net Framework 2到4和Monorail 1.0.3到2.1RC),我的ViewComponent类没有找到。我所有的控制器似乎都能正常工作。我正在使用nVelocity View Engine。我没有使用温莎,但现在我想以某种方式注册它?将单轨从v1.0.3升级到v2.1RC后未找到ViewComponent

在.vm文件,我尝试以下行(没有成功,第一个是工作之前我升级项目):

#component(MenuComponent) 
#component(MenuComponent with "role=admins") 
#blockcomponent(MenuComponent with "role=admins") 

没有人尝试呢?

完整的错误信息是:

ViewComponent 'MenuComponent的' 可能 不会被发现。是否注册?如果 已启用Windsor集成, ,那么很可能您忘记了 将视图组件注册为Windsor组件 Windsor组件。如果你确信你 做到了,那么请确保使用 名称是组件的ID或键传递 到ViewComponentDetailsAttribute

非常感谢!

+0

你如何在温莎注册? – jishi 2011-06-20 09:59:28

+0

对不起,我没有使用温莎,所以我不能帮你。也许你可以在代码示例中找到一些线索:http://groups.google.com/group/castle-project-users/browse_thread/thread/f8002e922dc04bee – 2011-06-20 15:02:23

+0

那么你如何注册组件和控制器?我不是在要求我,而是在问我为了帮助你。 – jishi 2011-06-20 15:28:41

回答

1

我终于找到了我的问题的线索。我使用'Castle.Monorail.Framework.dll'源代码来查看里面发生了什么:似乎在Web.Config文件中指定的程序集(在<Controllers>中,甚至在<viewcomponents>中)未被“检查”,因为它们应该是因为它们应该是因为包含它的变量被初始化得太晚。

我建立了一个新版本的DLL,现在它工作正常。我会将我的'固定'代码提交给Castle Project Community,以确保它不是别的东西的后果(比如糟糕的设置)。

然后这里是我的'修复',我只是移动了一部分代码。你可以找到原始的源代码的位置:http://www.symbolsource.org/Public/Metadata/Default/Project/Castle/1.0-RC3/Debug/All/Castle.MonoRail.Framework/Castle.MonoRail.Framework/Services/DefaultViewComponentFactory.cs

*Assembly:* Castle.MonoRail.Framework 
*Class:* Castle.MonoRail.Framework.Services.**DefaultViewComponentFactory** 


public override void Service(IServiceProvider provider) 
{ 
    /* Here is the section I moved */ 
    var config = (IMonoRailConfiguration)provider.GetService(typeof(IMonoRailConfiguration)); 
    if (config != null) 
    { 
    assemblies = config.ViewComponentsConfig.Assemblies; 
    if (assemblies == null || assemblies.Length == 0) 
    { 
     // Convention: uses the controller assemblies in this case 
     assemblies = config.ControllersConfig.Assemblies.ToArray(); 
    } 
    } 
    /*******************************/ 

    base.Service(provider); // Assemblies inspection is done there 

    var loggerFactory = (ILoggerFactory) provider.GetService(typeof(ILoggerFactory)); 
    if (loggerFactory != null) 
    { 
    logger = loggerFactory.Create(typeof(DefaultViewComponentFactory)); 
    } 
    /* The moved section was here */ 
} 
0

我很好奇,没有你们的修复,如果重命名MenuComponent的只是菜单,操作呢?

相关问题