开发者

ViewComponent not found after upgrading Monorail from v1.0.3 to v2.1RC

开发者 https://www.devze.com 2023-03-13 05:43 出处:网络
I\'m using Monorail in my C# web application. Since I upgrated it (.Net Framework 2 to 4 and Monorail 1.0.3 to 2.1RC), my ViewComponent class is not found. All my controllers seem to work fine. I\'m u

I'm using Monorail in my C# web application. Since I upgrated it (.Net Framework 2 to 4 and Monorail 1.0.3 to 2.1RC), my ViewComponent class is not found. All my controllers seem to work fine. I'm using nVelocity View Engine. I'm not using Windsor, but maybe now I'm suppose to register it in a certain way?

In the .vm file, I experimented the following lines (without success, the first one was working before I upgraded the project) :

开发者_如何学JAVA
 #component(MenuComponent)
 #component(MenuComponent with "role=admins")
 #blockcomponent(MenuComponent with "role=admins")

Did anyone experiment that?

The full error message is:

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

Many thanks!


I finally found a clue to my problem. I used 'Castle.Monorail.Framework.dll' source code to see what happen inside : it seems that assemblies specified in the Web.Config file (in <Controllers> or even in <viewcomponents>) are not 'inspected' as they are supposed to be because the variable which contains it is initialized too late.

I builded a new version of the dll and now it's working fine. I will submit my 'fixed' code to the Castle Project Community to be sure it's not the consequence of something else (like bad settings).

Til then here is my 'fix', I just moved a portion of code. You can find the original source code here : 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 */
}


I'm curious, without your fix, if you rename MenuComponent to just Menu, does it work?

0

精彩评论

暂无评论...
验证码 换一张
取 消