Skip to content

Instantly share code, notes, and snippets.

@antonydenyer
Created September 20, 2012 11:40
Show Gist options
  • Save antonydenyer/3755430 to your computer and use it in GitHub Desktop.
Save antonydenyer/3755430 to your computer and use it in GitHub Desktop.
ServiceStack SevenDigitalAppHost
public abstract class SevenDigitalAppHost : AppHostBase
{
protected SevenDigitalAppHost(string serviceName, params Assembly[] assembliesWithServices)
: base(serviceName, assembliesWithServices)
{
JsConfig.EmitCamelCaseNames = true;
JsConfig.DateHandler = JsonDateHandler.ISO8601;
Plugins.RemoveAll(x => x is AuthFeature);
Plugins.RemoveAll(x => x is SessionFeature);
Plugins.Add(new ValidationFeature(new ErrorResponseFactory()));
RegisterStatsDClient();
Plugins.Add(new RequestLogsFeature
{
RequiredRoles = new string[] { },
EnableErrorTracking = true,
EnableResponseTracking = true
});
SetConfig(new EndpointHostConfig
{
GlobalResponseHeaders = {
{ "Access-Control-Allow-Origin", "*" },
{ "Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS" },
{ "Access-Control-Allow-Headers", "Content-Type" },
{ "X-Powered-On", Environment.MachineName},
},
DebugMode = DebugMode(),
DefaultContentType = "application/json"
});
}
private bool DebugMode()
{
if (ConfigurationManager.AppSettings.AllKeys.Any(x => x == "app_ShowStackTrace"))
{
return bool.Parse(ConfigurationManager.AppSettings["app_ShowStackTrace"]);
}
return false;
}
private void RegisterStatsDClient()
{
try
{
IStatsd client = new Statsd(new StatsdUDP(ConfigurationManager.AppSettings["statsD_ServerName"],
int.Parse(ConfigurationManager.AppSettings["statsD_ServerPort"])));
Plugins.Add(new StatsDFeature(
client,
ConfigurationManager.AppSettings["statsD_Environment"] + "." +
ConfigurationManager.AppSettings["statsD_Application"] + "."
));
}
catch (ArgumentNullException)
{
Debug.WriteLine("Failed to load statsd client");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment