using System.Web.Mvc; using System.Web.Routing; using JetBrains.Annotations; using Microsoft.Practices.Unity; using Portoa.Logging; using Portoa.Search; using Portoa.Web; using Portoa.Web.Models; using Portoa.Web.Security; using Portoa.Web.SmartCasing; using Portoa.Web.Unity; using UnityGenerics; using VideoGameQuotes.Api; using VideoGameQuotes.Api.Persistence; 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>() .Add() .Add(); } protected override void ConfigureUnity() { Container .RegisterType(new InjectionProperty(attr => attr.UserProvider)) .RegisterAndIntercept, SessionBasedUserProvider>() .RegisterAndIntercept() .RegisterAndIntercept() .RegisterAndIntercept() .RegisterAndIntercept() .RegisterAndIntercept() .RegisterAndIntercept() .RegisterAndIntercept() .RegisterAndIntercept() .RegisterAndIntercept() .RegisterAndIntercept(); } protected override void AfterStartUp() { ViewEngines.Engines.Add(new SmartCaseViewEngine(Container.Resolve())); Container.Resolve>().BuildIndex(); } protected override void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.IgnoreRoute("media/{*anything}"); routes.MapRoute("favicon", "favicon.ico", new { controller = "Home", action = "Favicon" }); //bullshit route so that RenderAction works routes.MapSmartRoute("mainmenu", "home/mainmenu", new { controller = "Home", action = "MainMenu" }); routes.MapSmartRoute("quote-of-the-day", "quote/quoteoftheday", new { controller = "Quote", action = "QuoteOfTheDay" }); routes.MapSmartRoute("quote", "{action}", new { controller = "Quote" }, new { action = "submit|random|vote|flag|browse" }); routes.MapSmartRoute("crud-default", "{controller}/{action}", null, new { controller = "system|publisher|game|category", action = "create|edit|delete" }); routes.MapSmartRoute("admin-default", "admin", new { controller = "Admin", action = "Index" }); routes.MapSmartRoute("admin", "admin/{action}", new { controller = "Admin", action = "Index" }, new { action = "users|create|flags|password" }); routes.MapSmartRoute("user-edit", "user/edit/{usernameOrIp}", new { controller = "User", action = "Edit", usernameOrIp = @"\w+" }); routes.MapSmartRoute("api-no-criteria", "api/{action}/{id}", new { controller = "Api" }, new { action = "game|system|category|publisher|quote", id = @"\d+|all" }); routes.MapSmartRoute("api", "api/{action}/{id}/{*criteria}", new { controller = "Api" }, new { action = "game|system|category|publisher|quote", id = @"\d+|all" }); routes.MapSmartRoute("home", "{action}", new { controller = "Home", action = "Index" }, new { action = "about|contact|login|logout" }); routes.MapSmartRoute("paged-default", "{action}", new { controller = "Quote", page = 1 }, new { action = "best|recent" }); routes.MapSmartRoute("paged", "{action}/{page}", new { controller = "Quote", page = 1 }, new { action = "best|recent", page = @"\d+" }); routes.MapSmartRoute("browse", "browse/{*qualifiers}", new { controller = "Quote", action = "Browse" }); routes.MapSmartRoute("search", "search/{*searchQuery}", new { controller = "Quote", action = "Search" }); //these routes don't work with constraints in mono...? routes.MapSmartRoute("quote-edit", "quote/edit/{id}", new { controller = "Quote", action = "Edit" }); routes.MapSmartRoute("individual-quote-with-text", "quote/{id}/{*text}", new { controller = "Quote", action = "Quote" }); routes.MapSmartRoute("dismiss-flag", "dismiss-flag", new { controller = "Quote", action = "DismissFlag" }); routes.MapSmartRoute("default", "", new { controller = "Home", action = "Index" }); } } }