2011-06-16 41 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的只是菜單,操作呢?

相關問題