vgquotes/Src/VideoGameQuotes.Web/Global.asax.cs

95 lines
4.8 KiB
C#
Raw Normal View History

2011-02-22 04:05:23 +00:00
using System.Collections.Specialized;
2011-02-17 05:30:31 +00:00
using System.Configuration;
using System.Web.Mvc;
2011-02-09 03:50:45 +00:00
using System.Web.Routing;
2011-02-10 04:39:59 +00:00
using Microsoft.Practices.Unity;
2011-02-17 05:30:31 +00:00
using Portoa.Logging;
2011-02-10 04:39:59 +00:00
using Portoa.Web;
using Portoa.Web.Models;
using Portoa.Web.Security;
2011-02-10 04:39:59 +00:00
using Portoa.Web.Unity;
using UnityGenerics;
2011-02-10 04:39:59 +00:00
using VideoGameQuotes.Api;
using VideoGameQuotes.Api.Persistence;
2011-02-17 05:30:31 +00:00
using VideoGameQuotes.Api.Search;
using VideoGameQuotes.Api.Search.Lucene;
using VideoGameQuotes.Web.Controllers;
using VideoGameQuotes.Web.Models;
2011-02-10 04:39:59 +00:00
using VideoGameQuotes.Web.Security;
using VideoGameQuotes.Web.Services;
2011-02-09 03:50:45 +00:00
namespace VideoGameQuotes.Web {
public class MvcApplication : MvcApplicationBase<User> {
protected override void ConfigureModelBinders(ModelBinderDictionary binders) {
binders
.Add<Region, FlagEnumModelBinder<Region>>()
.Add<BrowseModel, BrowseModelBinder>()
.Add<ApiModel, ApiModelBinder>();
}
2011-02-10 04:39:59 +00:00
protected override void ConfigureUnity() {
Container
.AddNewExtension<ConfigureLog4Net>()
.Configure<ILog4NetConfigurator>()
.SetName("VideoGameQuotes.Web")
.UseXml();
2011-02-10 04:39:59 +00:00
Container
.AddNewExtension<LogAllMethodCalls>()
.RegisterType<ICurrentUserProvider<User>, SessionBasedUserProvider>()
.RegisterType<VerifyUserAttribute>(new InjectionProperty<VerifyUserAttribute>(attr => attr.UserProvider))
2011-02-10 04:39:59 +00:00
.RegisterType<IUserService, UserService>()
.RegisterType<IAdministrationService, AdministrationService>()
.RegisterType<IQuoteService, QuoteService>()
.RegisterType<ISystemService, SystemService>()
.RegisterType<IPublisherService, PublisherService>()
.RegisterType<IGameService, GameService>()
.RegisterType<IApiService, ApiService>()
.RegisterType<IAuthenticationService, FormsAuthenticationService>()
2011-02-17 05:30:31 +00:00
.RegisterType<IQuoteSearcher, LuceneQuoteSearcher>()
.RegisterType<ISearchIndexLocator, SearchIndexLocator>(new ContainerControlledLifetimeManager(), new InjectionFactory(CreateIndexLocator))
.RegisterType<IUserRepository, UserRepository>();
}
private static SearchIndexLocator CreateIndexLocator(IUnityContainer container) {
var indexDirectory = ((NameValueCollection)ConfigurationManager.GetSection("vgquotes"))["luceneIndexDirectory"];
return new SearchIndexLocator(indexDirectory);
2011-02-17 05:30:31 +00:00
}
protected override void AfterStartUp() {
var logger = Container.Resolve<ILogger>();
logger.Info("Building lucene index");
Container.Resolve<IQuoteSearcher>().BuildIndex();
logger.Info("Done building lucene index");
2011-02-10 04:39:59 +00:00
}
2011-02-09 03:50:45 +00:00
2011-02-10 04:39:59 +00:00
protected override void RegisterRoutes(RouteCollection routes) {
2011-02-09 03:50:45 +00:00
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
2011-02-10 04:39:59 +00:00
routes.IgnoreRoute("media/{*anything}");
2011-02-09 03:50:45 +00:00
//bullshit route so that RenderAction works
routes.MapRoute("mainmenu", "home/mainmenu", new { controller = "Home", action = "MainMenu" });
routes.MapRoute("crud-default", "{controller}/{action}", null, new { controller = "system|publisher|game", action = "create" });
routes.MapRoute("users-paged", "admin/users/{start}-{end}", new { controller = "Admin", action = "Users" }, new { start = @"\d+", end = @"\d+" });
routes.MapRoute("admin", "admin/{action}", new { controller = "Admin", action = "Index" }, new { action = "users|create|flags|password" });
routes.MapRoute("user-edit", "user/edit/{usernameOrIp}", new { controller = "User", action = "Edit", usernameOrIp = @"\w+" });
routes.MapRoute("user-default", "user/{action}/{id}", new { controller = "User", action = "delete|ban", id = UrlParameter.Optional });
routes.MapRoute("api", "api/{action}/{id}/{*criteria}", new { controller = "Api" }, new { action = "game|system|category|publisher|quote", id = @"\d+|all" });
routes.MapRoute("home", "{action}", new { controller = "Home", action = "Index" }, new { action = "about|contact|login|logout" });
2011-02-22 04:05:23 +00:00
routes.MapRoute("best", "best/{page}", new { controller = "Quote", action = "Best", page = 1 }, new { page = @"\d+" });
routes.MapRoute("browse", "browse/{*qualifiers}", new { controller = "Quote", action = "Browse" });
2011-02-17 05:30:31 +00:00
routes.MapRoute("search", "search/{*searchQuery}", new { controller = "Quote", action = "Search" });
routes.MapRoute("quote-task", "{action}/{id}", new { controller = "Quote" }, new { action = "edit|flags", id = @"\d+" });
2011-02-22 04:05:23 +00:00
routes.MapRoute("quote", "{action}", new { controller = "Quote" }, new { action = "submit|recent|random|vote|report" });
routes.MapRoute("dismiss-flag", "dismiss-flag", new { controller = "Quote", action = "DismissFlag" });
routes.MapRoute("individual-quote", "quote/{id}/{*text}", new { controller = "Quote", action = "Quote" }, new { id = @"\d+" });
2011-02-14 19:19:15 +00:00
routes.MapRoute("create-category", "category/create", new { controller = "Quote", action = "CreateCategory" });
2011-02-17 05:30:31 +00:00
routes.MapRoute("default", "{controller}", new { controller = "home", action = "index" });
2011-02-09 03:50:45 +00:00
}
}
}