-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathProgram.cs
More file actions
93 lines (80 loc) · 2.95 KB
/
Copy pathProgram.cs
File metadata and controls
93 lines (80 loc) · 2.95 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using Check.ServiceModel;
using Funq;
using ServiceStack;
using ServiceStack.Admin;
using ServiceStack.Auth;
using ServiceStack.Data;
using ServiceStack.OrmLite;
using ServiceStack.Text;
namespace CheckHttpListener
{
public class AppSelfHost : AppSelfHostBase
{
public static Rockstar[] SeedRockstars = new[] {
new Rockstar { Id = 1, FirstName = "Jimi", LastName = "Hendrix", Age = 27 },
new Rockstar { Id = 2, FirstName = "Jim", LastName = "Morrison", Age = 27 },
new Rockstar { Id = 3, FirstName = "Kurt", LastName = "Cobain", Age = 27 },
new Rockstar { Id = 4, FirstName = "Elvis", LastName = "Presley", Age = 42 },
new Rockstar { Id = 5, FirstName = "David", LastName = "Grohl", Age = 44 },
new Rockstar { Id = 6, FirstName = "Eddie", LastName = "Vedder", Age = 48 },
new Rockstar { Id = 7, FirstName = "Michael", LastName = "Jackson", Age = 50 },
};
public AppSelfHost()
: base("DocuRec Services", typeof(TestService).Assembly)
{ }
public override void Configure(Container container)
{
container.Register<IDbConnectionFactory>(
new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider));
using (var db = container.Resolve<IDbConnectionFactory>().Open())
{
db.DropAndCreateTable<Rockstar>();
db.InsertAll(SeedRockstars);
}
Plugins.Add(new AutoQueryFeature { MaxLimit = 100 });
Plugins.Add(new AdminFeature());
Plugins.Add(new AuthFeature(() => new AuthUserSession(),
new [] { new BasicAuthProvider(AppSettings) })
{
ServiceRoutes = new Dictionary<Type, string[]> {
{ typeof(AuthenticateService), new[] { "/api/auth", "/api/auth/{provider}" } },
}
});
SetConfig(new HostConfig
{
CompressFilesWithExtensions = { "html", "js" }
});
}
public override RouteAttribute[] GetRouteAttributes(Type requestType)
{
var routes = base.GetRouteAttributes(requestType);
routes.Each(x => x.Path = "/api" + x.Path);
return routes;
}
}
[Route("/query/rockstars")]
public class QueryRockstars : QueryDb<Rockstar> { }
//public class Hello { }
public class TestService : Service
{
//public object Any(Hello request)
//{
// return request;
//}
}
internal class Program
{
private static void Main(string[] args)
{
var appHost = new AppSelfHost()
.Init()
.Start("http://127.0.0.1:2222/");
Process.Start("http://127.0.0.1:2222/");
Console.ReadLine();
}
}
}