2010-07-17 10:51:07 -07:00
|
|
|
|
using System.Linq;
|
2010-04-14 10:28:33 -07:00
|
|
|
|
using System.Web;
|
|
|
|
|
|
using System.Web.Mvc;
|
|
|
|
|
|
using System.Web.Routing;
|
|
|
|
|
|
using Autofac;
|
|
|
|
|
|
using Orchard.Environment;
|
2010-04-21 19:41:37 -07:00
|
|
|
|
using Orchard.Environment.Configuration;
|
2010-04-14 10:28:33 -07:00
|
|
|
|
|
2010-06-05 23:04:56 -07:00
|
|
|
|
namespace Orchard.Specs.Hosting.Orchard.Web {
|
|
|
|
|
|
public class MvcApplication : HttpApplication {
|
2010-04-21 19:41:37 -07:00
|
|
|
|
private static IContainer _hostContainer;
|
2010-04-14 10:28:33 -07:00
|
|
|
|
private static IOrchardHost _host;
|
|
|
|
|
|
|
2010-06-05 23:04:56 -07:00
|
|
|
|
protected void Application_Start() {
|
2010-04-21 19:41:37 -07:00
|
|
|
|
_hostContainer = OrchardStarter.CreateHostContainer(MvcSingletons);
|
|
|
|
|
|
_host = _hostContainer.Resolve<IOrchardHost>();
|
|
|
|
|
|
Host.Initialize();
|
2010-04-14 10:28:33 -07:00
|
|
|
|
|
|
|
|
|
|
var route = RouteTable.Routes.MapRoute("foo", "hello-world", new { controller = "Home", action = "Index" });
|
|
|
|
|
|
route.RouteHandler = new HelloYetAgainHandler();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2010-06-05 23:04:56 -07:00
|
|
|
|
protected void Application_BeginRequest() {
|
2010-04-21 19:41:37 -07:00
|
|
|
|
Host.BeginRequest();
|
2010-04-14 10:28:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2010-06-05 23:04:56 -07:00
|
|
|
|
protected void Application_EndRequest() {
|
2010-04-21 19:41:37 -07:00
|
|
|
|
Host.EndRequest();
|
2010-04-14 10:28:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2010-06-05 23:04:56 -07:00
|
|
|
|
protected void MvcSingletons(ContainerBuilder builder) {
|
2010-04-14 10:28:33 -07:00
|
|
|
|
builder.RegisterInstance(ControllerBuilder.Current);
|
|
|
|
|
|
builder.RegisterInstance(RouteTable.Routes);
|
|
|
|
|
|
builder.RegisterInstance(ModelBinders.Binders);
|
|
|
|
|
|
builder.RegisterInstance(ModelMetadataProviders.Current);
|
|
|
|
|
|
builder.RegisterInstance(ViewEngines.Engines);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2010-04-21 19:41:37 -07:00
|
|
|
|
public static IOrchardHost Host {
|
|
|
|
|
|
get { return _host; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2010-07-17 10:51:07 -07:00
|
|
|
|
public static void ReloadExtensions() {
|
|
|
|
|
|
_host.ReloadExtensions();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2010-09-02 16:34:17 -07:00
|
|
|
|
public static IWorkContextScope CreateStandaloneEnvironment(string name) {
|
2010-04-21 19:41:37 -07:00
|
|
|
|
var settings = _hostContainer.Resolve<IShellSettingsManager>().LoadSettings().SingleOrDefault(x => x.Name == name);
|
|
|
|
|
|
return Host.CreateStandaloneEnvironment(settings);
|
|
|
|
|
|
}
|
2010-04-14 10:28:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|