/
AppHost.cs
57 lines (42 loc) · 1.72 KB
/
AppHost.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using Api.RestHandlers;
using Api.RestHandlers.Handlers;
using Api.RestHandlers.Validators;
using Core;
using ServiceStack.CacheAccess;
using ServiceStack.CacheAccess.Providers;
using ServiceStack.ServiceInterface.Admin;
using ServiceStack.ServiceInterface.Validation;
using ServiceStack.WebHost.Endpoints;
namespace Api.RestServiceHost.App_Start
{
public class AppHost
: AppHostBase
{
public AppHost() //Tell ServiceStack the name and where to find your web services
: base("StarterTemplate ASP.NET Host", typeof(EmptyExampleHandler).Assembly) { }
public override void Configure(Funq.Container container)
{
//Set JSON web services to return idiomatic JSON camelCase properties
ServiceStack.Text.JsConfig.EmitCamelCaseNames = true;
ApiRegistration.Register(Routes);
//Change the default ServiceStack configuration
SetConfig(new EndpointHostConfig
{
DebugMode = true, //Show StackTraces in responses in development
//enable CORS
GlobalResponseHeaders = { { "Access-Control-Allow-Origin", "*" },
{ "Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS" },
{ "Access-Control-Allow-Headers", "Content-Type" },
}
});
Plugins.Add(new ValidationFeature());
container.RegisterValidators(typeof(ApplicationRequestValidator).Assembly);
Plugins.Add(new RequestLogsFeature());
//Register In-Memory Cache provider.
//For Distributed Cache Providers Use: PooledRedisClientManager, BasicRedisClientManager or see: https://github.com/ServiceStack/ServiceStack/wiki/Caching
container.Register<ICacheClient>(new MemoryCacheClient());
//Set MVC to use the same Funq IOC as ServiceStack
ServiceRegistration.RegisterAllContainers(container);
}
}
}