public class AddJsonToViewsPolicy : Policy
{
public AddJsonToViewsPolicy()
{
Where.RespondsToHttpMethod("GET")
.And.ChainMatches(c=>c.InputType().CanBeCastTo<IAlsoOutputJSON>());
ModifyBy(chain =>
{
chain.Input.AddFormatter<JsonFormatter>();
chain.Output.AddFormatter<JsonFormatter>();
});
}
}
Adding this policy actually caused a runtime error in Fubu 1.3 complaining that one of my chains had no input behavior.
Before posting to the list for help I searched and found
this thread where we discussed this exact thing. Sadly, I had participated in the thread but forgot about it. RobertTheGrey’s policy lambda does the trick:
//Added to my web FubuRegistry to Ensure that search requests return JSON AND their HTML view
Policies.Add(x =>
{
x.Conneg.AcceptJson();
x.ModifyBy(chain => chain.OutputJson());
x.Where.ResourceTypeImplements<IAlsoOutputJSON>();
});