Skip to content

Instantly share code, notes, and snippets.

@robashton
Created February 7, 2011 18:50
Show Gist options
  • Save robashton/814937 to your computer and use it in GitHub Desktop.
Save robashton/814937 to your computer and use it in GitHub Desktop.
WomRegistry
public static class Bootstrapper
{
public static void Startup()
{
var documentStore = new EmbeddableDocumentStore
{
Configuration = new RavenConfiguration
{
DataDirectory = "App_Data\\RavenDB",
}
};
documentStore.Initialize();
ObjectFactory.Initialize(config => config.AddRegistry(new CoreRegistry(documentStore)));
IndexCreation.CreateIndexes(typeof(MonoVersionIndex).Assembly, documentStore);
FubuApplication
.For<WomRegistry>()
.StructureMapObjectFactory()
.Bootstrap(RouteTable.Routes);
}
}
public class MvcApplication : HttpApplication
{
protected void Application_Start()
{
Bootstrapper.Startup();
}
}
public class WomServiceUrlPolicy : IUrlPolicy
{
public bool Matches(ActionCall call, IConfigurationObserver log)
{
return call.HandlerType.Namespace.StartsWith("Wom.Services");
}
public IRouteDefinition Build(ActionCall call)
{
// And the route looks something like /Services/ResourceType/Action
var ns = call.HandlerType.Namespace.Split('.').Last();
var route = call.ToRouteDefinition();
route.Append("services");
route.Append(ns);
route.Append(call.HandlerType.Name);
return route;
}
}
public class WomViewUrlPolicy : IUrlPolicy
{
public bool Matches(ActionCall call, IConfigurationObserver log)
{
// This policy is global
return call.HandlerType.Namespace.StartsWith("Wom.Views");
}
public IRouteDefinition Build(ActionCall call)
{
var ns = call.HandlerType.Namespace.Split('.').Last();
var route = call.ToRouteDefinition();
route.Append(ns);
route.Append(call.HandlerType.Name);
return route;
}
}
public class WomRegistry : FubuRegistry
{
public static string[] Verbs =
{
"Get",
"Post"
};
public WomRegistry()
{
IncludeDiagnostics(true);
Applies
.ToThisAssembly();
Policies.WrapBehaviorChainsWith<ServiceValidationBehaviour>();
Actions
.IncludeTypes(x => x.Namespace.StartsWith("Wom.Views"))
.IncludeTypes(x => x.Namespace.StartsWith("Wom.Services"))
.IncludeMethods(x => Verbs.Contains(x.Method.Name));
Routes
.ConstrainToHttpMethod(x => x.Method.Name == "Get", "GET")
.ConstrainToHttpMethod(x => x.Method.Name == "Post", "POST")
.UrlPolicy<WomViewUrlPolicy>()
.UrlPolicy<WomServiceUrlPolicy>();
this.Spark(spark => spark
.Policies
.Add<WomSparkPolicy>());
Output
.ToJson
.WhenTheOutputModelIs<JsonResponse>();
HomeIs<Index>(c => c.Get());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment