Created
April 14, 2010 18:27
-
-
Save jglozano/366149 to your computer and use it in GitHub Desktop.
shows how the system can handle registration of MVC2 Areas out of the box.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Provides the auto-registration of MVC related components (controllers, view engines, filters, etc). | |
/// </summary> | |
/// <param name="registrationList"></param> | |
public virtual void AddRegistrations(AutoRegistrationList registrationList) { | |
registrationList | |
.Add(MvcRegistration.RegisterController()) | |
.Add(MvcRegistration.RegisterViewEngine()) | |
.Add(MvcRegistration.RegisterFilter<IActionFilter>()) | |
.Add(MvcRegistration.RegisterFilter<IResultFilter>()) | |
.Add(MvcRegistration.RegisterFilter<IAuthorizationFilter>()) | |
.Add(MvcRegistration.RegisterFilter<IExceptionFilter>()) | |
.Add(MvcRegistration.RegisterBinder()) | |
// Register all AreaRegistrations in the AppDomain | |
.Add(MvcRegistration.RegisterAreas()); | |
} | |
/// <summary> | |
/// Setups the areas for an MVC application | |
/// </summary> | |
/// <param name="context">The context.</param> | |
public virtual void SetupAreas(IRotorContext context) { | |
var serviceLocator = GetServiceLocatorFromContext(context); | |
IList<AreaRegistration> areaRegistrations = GetAreaRegistrations(serviceLocator); | |
if (areaRegistrations == null) return; | |
foreach (var areaRegistration in areaRegistrations) { | |
var registrationContext = new AreaRegistrationContext(areaRegistration.AreaName, RouteTable.Routes); | |
areaRegistration.RegisterArea(registrationContext); | |
} | |
} | |
/// <summary> | |
/// Gets the <see cref="AreaRegistration"/> that have been auto-registered with the system. | |
/// </summary> | |
/// <param name="serviceLocator"></param> | |
/// <returns></returns> | |
protected virtual IList<AreaRegistration> GetAreaRegistrations(IServiceLocator serviceLocator) { | |
try { | |
return serviceLocator.ResolveServices<AreaRegistration>(); | |
} catch { | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment