code generator question (the chicken or the egg)

0 views
Skip to first unread message

Ernst Naezer

unread,
Mar 20, 2007, 4:43:46 AM3/20/07
to castle-pro...@googlegroups.com
Hi guys,

I'm experimenting with the code generator contrib and I really like the way it kills string literals :) nice.

There is one question I have (perhaps this is really obvious)

When it indexes Views it tries to match directories that end with 'Controller',
so the view folder should look something like:

Views\
  HomeController\
     index.brail
  UserController\
     index.brail

The parser work fine and it updates MyViews. Then I surf to /home/index.rails and MR tells me it can't locate :

Views\Home\index.brail

It strips the Controller suffix. I rename the 'HomeController' directory to 'Home', MR works fine but the code generator doesn't pick up the changes... :(
It there and easy way to fix this?

cheers,

Ernst.




 

Lee Henson

unread,
Mar 20, 2007, 5:14:18 AM3/20/07
to Castle Project Development List
I don't have any Controller suffixes on my View subfolders. How have
you got your generator configured?

> ------=_Part_55722_14384925.1174380226721
> Content-Type: text/html; charset=ISO-8859-1
> X-Google-AttachSize: 1329
>
> Hi guys,<br><br>I&#39;m experimenting with the code generator contrib and I really like the way it kills string literals :) nice. <br><br>There is one question I have (perhaps this is really obvious)<br><br>When it indexes Views it tries to match directories that end with &#39;Controller&#39;,
> <br>so the view folder should look something like:<br><br style="font-weight: bold;"><span style="font-weight: bold;">Views\</span><br style="font-weight: bold;"><span style="font-weight: bold;">&nbsp; HomeController\ </span>
> <br style="font-weight: bold;"><span style="font-weight: bold;">&nbsp;&nbsp; &nbsp; index.brail</span><br style="font-weight: bold;"><span style="font-weight: bold;">&nbsp; UserController\</span><br style="font-weight: bold;"><span style="font-weight: bold;">
> &nbsp; &nbsp;&nbsp; index.brail</span><br style="font-weight: bold;"><br>The parser work fine and it updates MyViews. Then I surf to /home/index.rails and MR tells me it can&#39;t locate :<br><br><span style="font-weight: bold;">Views\Home\index.brail
> </span><br><br>It strips the Controller suffix. I rename the &#39;HomeController&#39; directory to &#39;Home&#39;, MR works fine but the code generator doesn&#39;t pick up the changes... :(<br>It there and easy way to fix this?
> <br><br>cheers,<br><br>Ernst.<br><br><br><br><br>&nbsp; <br><br>
>
> ------=_Part_55722_14384925.1174380226721--

Ernst Naezer

unread,
Mar 20, 2007, 5:27:05 AM3/20/07
to castle-pro...@googlegroups.com
It looks like this:

  <ItemGroup>
    <ViewSources Include="Views\**\*.brail">
      <InProject>false</InProject>
    </ViewSources>
    <ControllerSources Include="Controllers\**\*.cs">
      <InProject>false</InProject>
    </ControllerSources>
    <ViewComponentSources Include="Components\**\*.cs">
      <InProject>false</InProject>
    </ViewComponentSources>
  </ItemGroup>

  <Target Name="BeforeBuild" Inputs="@(Compile)" Outputs="$(ProjectDir)\SiteMap.generated.cs" DependsOnTargets="ResolveReferences">
    <GenerateMonoRailSiteTreeTask OutputFile=" SiteMap.generated.cs" Namespace="Niveon.WebApplication.SiteMap" ControllerSources="@(ControllerSources)" ViewSources="@(ViewSources)" Sources="@(Compile)" ViewComponentSources="@(ViewComponentSources)" AssemblyReferences="@(ReferencePath);@(_ResolvedProjectReferencePaths)">
    </GenerateMonoRailSiteTreeTask>
  </Target>

Ernst Naezer

unread,
Mar 20, 2007, 5:30:07 AM3/20/07
to castle-pro...@googlegroups.com
Perhaps I'm doing something wrong with my controller?

it looks like this:

    public partial class HomeController : ControllerBase
    {
     ...
    }



    [Layout("default")]
    public abstract class ControllerBase : ARSmartDispatcherController
    {
        private ICodeGeneratorServices _services;

        public ICodeGeneratorServices CodeGeneratorServices
        {
            get { return _services; }
        }

        public RootAreaNode Site
        {
            get { return new RootAreaNode(_services); }
        }

        protected virtual void PerformGeneratedInitialize()
        {
            _services =
                new DefaultCodeGeneratorServices(new DefaultControllerReferenceFactory(), new AspDotNetRedirectService(),
                                                 new DefaultArgumentConversionService(), new DefaultRuntimeInformationService());
            _services.Controller = this;
        }

        protected override void Initialize()
        {
            base.Initialize();

            PerformGeneratedInitialize();

Lee Henson

unread,
Mar 20, 2007, 5:55:52 AM3/20/07
to Castle Project Development List
The controller looks fine, and the only difference I can see in the
config is that my Sources declaration looks like this (ignore the
WizardStepSources bit, it's not doing anything at the moment):

Sources="@(ControllerSources);@(WizardStepSources);@(ViewSources)"

But your @Compile may also be right, I'm not really an MSBuild user.

chriso

unread,
Mar 20, 2007, 9:55:24 AM3/20/07
to Castle Project Development List
Renaming should fix this. I'm thinking the error you get when the
folder is called HomeController is actually an error raised by MR?

I think you're running into one of 2 things:
1) After you rename sitemap.generated.cs is not getting recreated
because the folder rename doesn't trigger a rebuild. Just delete the
file and build, or do a Rebuild (i'm not sure on rebuild so make some
really obvsious change in sitemap.generated.cs and make sure it gets
recreated)

2) Is your CodeGeneratedServices coming from windsor and not getting
recreated after making the change because the web application doesn't
restart? touch web.config or iisreset.

Jacob Lewallen

unread,
Mar 20, 2007, 5:19:57 PM3/20/07
to castle-pro...@googlegroups.com
Anyone using the code generator should be careful to ensure the
CodeGeneratorServices is transient (if you only inject it once into
the controller) or perwebrequest if you consume it elsewhere, as it
stores a reference to the Controller.

jacob

Ernst Naezer

unread,
Mar 21, 2007, 7:02:22 AM3/21/07
to castle-pro...@googlegroups.com
Yeah, MR is the one throwing the exception, I removed the generated file and did a rebuild, it seems to be working now. Thanks!
I'm doing a new DefaultCodeGeneratedServices() in the PerformGeneratedInitialize function so I'm safe with the reference to the Controller, but thanks for the transient warning!

I'm going to replacing more strings :)

cheers,

Ernst.

Reply all
Reply to author
Forward
0 new messages