Skip to content

Instantly share code, notes, and snippets.

@flq
Created May 6, 2011 13:28
Show Gist options
  • Save flq/958950 to your computer and use it in GitHub Desktop.
Save flq/958950 to your computer and use it in GitHub Desktop.
Current Fubu registry
using FubuMVC.Core;
namespace CharmSim.Controllers
{
public class HelpController
{
public HelpViewModel Start()
{
return new HelpViewModel { Title = "Hello from Controller! " };
}
public HelpViewModel SomethingElse(HelpInputModel input)
{
return new HelpViewModel { Title = "Hello from Controller! " + input.HelpId };
}
}
public class HelpInputModel
{
public HelpInputModel(string helpId)
{
HelpId = helpId;
}
[RouteInput]
public string HelpId { get; set; }
}
public class HelpViewModel
{
public string Title { get; set; }
}
}
public class CharmSimRegistry : FubuRegistry
{
public CharmSimRegistry()
{
IncludeDiagnostics(true);
Applies.ToThisAssembly();
Actions.IncludeClassesSuffixedWithController();
this.WithSparkDefaults();
Routes
.IgnoreControllerNamespaceEntirely()
.UrlPolicy<CharmSimUrlPolicy>()
.HomeIs<HelpController>(c => c.Start());
}
}
<viewdata model="CharmSim.Controllers.HelpViewModel" />
<content:title>Charms System simulator</content:title>
<content:header>Charms System simulator</content:header>
<h1>${Model.Title}</h1>
<a href="${this.Urls.UrlFor(new HelpInputModel("23"))}">bla</p>
<p>!{this.LinkTo(new HelpInputModel("fr")).Text("Go Here")}</p>
public class CharmSimUrlPolicy : IUrlPolicy
{
public bool Matches(ActionCall call, IConfigurationObserver log)
{
return call.HandlerType.Name.EndsWith("Controller");
}
public IRouteDefinition Build(ActionCall call)
{
var route = call.ToRouteDefinition();
route.Append(call.HandlerType.Name.RemoveSuffix("Controller"));
route.Append(call.Method.Name);
return route;
}
}
@jeremydmiller
Copy link

Is your HomeController in the same assembly as your CharmSimRegistry?

@flq
Copy link
Author

flq commented May 6, 2011

Yes, it's all one assembly...but isn't it the behaviour you expect? The action I use as Home does not enter the UrlPolicy. This also happens in the HelloSpark app in fubu, I checked via /_fubu/routes

@jeremydmiller
Copy link

The action matching should have hit the HomeController and added the two actions to the BehaviorGraph just fine. Yes, the CharmSimUrlPolicy should never hit the HomeController.Start method because it already has a Route (HomeIs adds a route with "" as the pattern). You should see the SomethingElse() in your _fubu/chains view

@flq
Copy link
Author

flq commented May 6, 2011

That's settled then, thanks for your time...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment