Permalink
Find file
76fb971 Feb 24, 2015
53 lines (43 sloc) 1.8 KB
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
{
public class AppHost : AppHostBase
{
public AppHost() : base("Test Razor", typeof(AppHost).Assembly) { }
public override void Configure(Container container)
{
LogManager.LogFactory = new ConsoleLogFactory();
Plugins.Add(new RazorFormat());
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
SetConfig(new HostConfig { DebugMode = true });
}
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(),
}
));
}
}
}