Created
January 30, 2013 17:59
-
-
Save pdwetz/4675198 to your computer and use it in GitHub Desktop.
JsonBindingConvention for FubuMVC; tells it to use Json.Net for parsing input models for the JsonInput attribute.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using FubuMVC.Core.Registration; | |
using FubuMVC.Core.Registration.Nodes; | |
using FubuMVC.Core.Resources.Conneg; | |
using FubuMVC.Core.Runtime.Formatters; | |
using FubuMVC.Json; | |
public class JsonBindingConvention : IConfigurationAction | |
{ | |
public void Configure(BehaviorGraph graph) | |
{ | |
graph | |
.Behaviors | |
.Where(c => c.FirstCall().HasAttribute<JsonInputAttribute>()) | |
.Each(chain => chain.UseJsonBinding()); | |
} | |
} | |
public static class JsonBinder | |
{ | |
public static void UseJsonBinding(this BehaviorChain chain) | |
{ | |
chain.ApplyConneg(); | |
chain.Output.AddFormatter<JsonFormatter>(); | |
chain.Input.ClearAll(); | |
chain.Input.Readers.Prepend(new NewtonSoftReaderNode(chain.InputType())); | |
} | |
} | |
public class JsonInputAttribute : Attribute { } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment