84 lines
3.8 KiB
C#
84 lines
3.8 KiB
C#
using System.Collections.Specialized;
|
|
using System.Configuration;
|
|
using System.Web.Mvc;
|
|
using System.Web.Routing;
|
|
using Microsoft.Practices.Unity;
|
|
using Portoa.Logging;
|
|
using Portoa.Web;
|
|
using Portoa.Web.Models;
|
|
using Portoa.Web.Security;
|
|
using Portoa.Web.Unity;
|
|
using UnityGenerics;
|
|
using VideoGameQuotes.Api;
|
|
using VideoGameQuotes.Api.Persistence;
|
|
using VideoGameQuotes.Api.Search;
|
|
using VideoGameQuotes.Api.Search.Lucene;
|
|
using VideoGameQuotes.Web.Controllers;
|
|
using VideoGameQuotes.Web.Models;
|
|
using VideoGameQuotes.Web.Security;
|
|
using VideoGameQuotes.Web.Services;
|
|
|
|
namespace VideoGameQuotes.Web {
|
|
public class MvcApplication : MvcApplicationBase {
|
|
|
|
protected override void ConfigureModelBinders(ModelBinderDictionary binders) {
|
|
binders
|
|
.Add<Region, FlagEnumModelBinder>()
|
|
.Add<BrowseModel, BrowseModelBinder>()
|
|
.Add<ApiModel, ApiModelBinder>();
|
|
}
|
|
|
|
protected override void ConfigureUnity() {
|
|
Container
|
|
.AddNewExtension<ConfigureLog4Net>()
|
|
.Configure<ILog4NetConfigurator>()
|
|
.SetName("VideoGameQuotes.Web")
|
|
.UseXml();
|
|
|
|
Container
|
|
.AddNewExtension<LogAllMethodCalls>()
|
|
.RegisterType<ICurrentUserProvider, SessionBasedUserProvider>()
|
|
.RegisterType<IsValidUserAttribute>(new InjectionProperty<IsValidUserAttribute>(attr => attr.UserProvider))
|
|
.RegisterType<IUserService, UserService>()
|
|
.RegisterType<IAdministrationService, AdministrationService>()
|
|
.RegisterType<IQuoteService, QuoteService>()
|
|
.RegisterType<IApiService, ApiService>()
|
|
.RegisterType<IAuthenticationService, FormsAuthenticationService>()
|
|
.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);
|
|
}
|
|
|
|
protected override void AfterStartUp() {
|
|
var logger = Container.Resolve<ILogger>();
|
|
logger.Info("Building lucene index");
|
|
Container.Resolve<IQuoteSearcher>().BuildIndex();
|
|
logger.Info("Done building lucene index");
|
|
}
|
|
|
|
protected override void RegisterRoutes(RouteCollection routes) {
|
|
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
|
|
routes.IgnoreRoute("media/{*anything}");
|
|
|
|
//bullshit route so that RenderAction works
|
|
routes.MapRoute("mainmenu", "home/mainmenu", new { controller = "Home", action = "MainMenu" });
|
|
|
|
routes.MapRoute("admin", "admin/{action}", new { controller = "Admin", action = "Index" });
|
|
|
|
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" });
|
|
routes.MapRoute("best", "best/{start}-{end}/", new { controller = "Quote", action = "Best" }, new { start = @"\d+", end = @"\d+" });
|
|
routes.MapRoute("browse", "browse/{*qualifiers}", new { controller = "Quote", action = "Browse" });
|
|
routes.MapRoute("search", "search/{*searchQuery}", new { controller = "Quote", action = "Search" });
|
|
routes.MapRoute("quote", "{action}", new { controller = "Quote" }, new { action = "submit|recent|random|best|vote|report" });
|
|
routes.MapRoute("individual-quote", "quote/{id}/{*text}", new { controller = "Quote", action = "Quote" }, new { id = @"\d+" });
|
|
routes.MapRoute("create-category", "category/create", new { controller = "Quote", action = "CreateCategory" });
|
|
routes.MapRoute("default", "{controller}", new { controller = "home", action = "index" });
|
|
}
|
|
}
|
|
} |