Adding mvc3/razor placeholder support

Unofficial bits - do not use.
Integrates with mvc3 CSL hooks
Adds razor view engine to default configuration

--HG--
branch : mvc3p1
This commit is contained in:
Louis DeJardin
2010-08-23 13:10:12 -07:00
parent 585cd56c69
commit 4a84a0d591
33 changed files with 990 additions and 858 deletions

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
@@ -22,17 +23,10 @@ namespace Orchard.Web {
}
protected void Application_Start() {
// This is temporary until MVC3 is officially released.
// We want to avoid running against an outdated preview installed in the GAC
CheckMvcVersion(
new Version("3.0.10714.0")/*MVC3 Preview 1 file version #*/);
RegisterRoutes(RouteTable.Routes);
_host = OrchardStarter.CreateHost(MvcSingletons);
_host.Initialize();
//TODO: what's the failed initialization story - IoC failure in app start can leave you with a zombie appdomain
}
protected void Application_BeginRequest() {
@@ -45,58 +39,11 @@ namespace Orchard.Web {
_host.EndRequest();
}
private void CheckMvcVersion(params Version[] allowedVersions) {
Assembly loadedMvcAssembly = typeof(System.Web.Mvc.Controller).Assembly;
Version loadedMvcVersion = ReadAssemblyFileVersion(loadedMvcAssembly);
if (allowedVersions.All(allowed => loadedMvcVersion != allowed)) {
string message;
if (loadedMvcAssembly.GlobalAssemblyCache) {
message = string.Format(
"Orchard has been deployed with a version of {0} that has a different file version ({1}) " +
"than the version installed in the GAC ({2}).\r\n" +
"This implies that Orchard will not be able to run properly in this machine configuration.\r\n" +
"Please un-install MVC from the GAC or install a more recent version.",
loadedMvcAssembly.GetName().Name,
allowedVersions.First(),
loadedMvcVersion);
}
else {
message = string.Format(
"Orchard has been configured to run with a file version {1} of \"{0}\" " +
"but the version deployed with the application is {2}.\r\n" +
"This probably implies that Orchard is deployed with a newer version " +
"and the source code hasn't been updated accordingly.\r\n" +
"Update the Orchard.Web application source code (look for \"CheckMvcVersion\") to " +
"specify the correct file version number.\r\n",
loadedMvcAssembly.GetName().Name,
allowedVersions.First(),
loadedMvcVersion);
}
throw new HttpException(500, message);
}
static void MvcSingletons(ContainerBuilder builder) {
builder.Register(ctx => RouteTable.Routes).SingleInstance();
builder.Register(ctx => ModelBinders.Binders).SingleInstance();
builder.Register(ctx => ViewEngines.Engines).SingleInstance();
}
private Version ReadAssemblyFileVersion(Assembly assembly) {
object[] attributes = assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true);
if (attributes == null || attributes.Length != 1) {
string message = string.Format("Assembly \"{0}\" doesn't have a \"{1}\" attribute",
assembly.GetName().Name, typeof(AssemblyFileVersionAttribute).FullName);
throw new FileLoadException(message);
}
var attribute = (AssemblyFileVersionAttribute)attributes[0];
return new Version(attribute.Version);
}
protected void MvcSingletons(ContainerBuilder builder) {
builder.RegisterInstance(ControllerBuilder.Current);
builder.RegisterInstance(RouteTable.Routes);
builder.RegisterInstance(ModelBinders.Binders);
builder.RegisterInstance(ModelMetadataProviders.Current);
builder.RegisterInstance(ViewEngines.Engines);
}
}
}