Commit dc9250ca authored by yangxiaodong's avatar yangxiaodong

add json dispatcher.

parent 8d5b1ffc
using System;
using System.Net;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
namespace DotNetCore.CAP.Dashboard
{
internal class JsonDispatcher : IDashboardDispatcher
{
private readonly Func<DashboardContext, object> _command;
public JsonDispatcher(Func<DashboardContext, object> command)
{
_command = command;
}
public async Task Dispatch(DashboardContext context)
{
var request = context.Request;
var response = context.Response;
object result = _command(context);
var settings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
Converters = new JsonConverter[] { new StringEnumConverter { CamelCaseText = true } }
};
var serialized = JsonConvert.SerializeObject(result, settings);
context.Response.ContentType = "application/json";
await context.Response.WriteAsync(serialized);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment