forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppHost.cs
More file actions
57 lines (46 loc) · 1.84 KB
/
AppHost.cs
File metadata and controls
57 lines (46 loc) · 1.84 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
using System.Net;
using Funq;
using ServiceStack;
using ServiceStack.Auth;
using ServiceStack.Data;
using ServiceStack.Logging;
using ServiceStack.OrmLite;
using ServiceStack.Razor;
//The entire C# code for the stand-alone RazorRockstars demo.
namespace RazorRockstars.WebHost
{
using System.Reflection;
public class AppHost : AppHostBase
{
public AppHost() : base("Test Razor", typeof(Rockstar).Assembly) { }
public override void Configure(Container container)
{
LogManager.LogFactory = new ConsoleLogFactory();
Plugins.Add(new RazorFormat {
LoadFromAssemblies = { typeof(Rockstar).Assembly },
EnableLiveReload = true,
});
container.Register<IDbConnectionFactory>(
new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider));
using (var db = container.Resolve<IDbConnectionFactory>().OpenDbConnection())
{
db.CreateTableIfNotExists<Rockstar>();
db.InsertAll(RockstarsService.SeedData);
}
this.CustomErrorHttpHandlers[HttpStatusCode.NotFound] = new RazorHandler("/notfound");
this.CustomErrorHttpHandlers[HttpStatusCode.Unauthorized] = new RazorHandler("/login");
//AddAuthentication(container); //Uncomment to enable User Authentication
}
private void AddAuthentication(Container container)
{
container.Register<IUserAuthRepository>(c =>
new OrmLiteAuthRepository(c.Resolve<IDbConnectionFactory>()));
container.Resolve<IUserAuthRepository>().InitSchema();
Plugins.Add(new AuthFeature(() => new AuthUserSession(),
new IAuthProvider[] {
new CredentialsAuthProvider(),
}
));
}
}
}