diff --git a/src/Orchard.Web/Packages/Orchard.Setup/Routes.cs b/src/Orchard.Web/Packages/Orchard.Setup/Routes.cs index 80a8f59f8..2bc323f36 100644 --- a/src/Orchard.Web/Packages/Orchard.Setup/Routes.cs +++ b/src/Orchard.Web/Packages/Orchard.Setup/Routes.cs @@ -15,13 +15,16 @@ namespace Orchard.Setup { return new[] { new RouteDescriptor { Route = new Route( - "Setup", + "{controller}/{action}", new RouteValueDictionary { {"area", "Orchard.Setup"}, - {"controller", "Orchard.Setup"}, + {"controller", "Setup"}, {"action", "Index"} }, - new RouteValueDictionary(), + new RouteValueDictionary { + {"area", "Orchard.Setup"}, + {"controller", "Setup"}, + }, new RouteValueDictionary { {"area", "Orchard.Setup"} }, diff --git a/src/Orchard/Environment/ShellBuilders/SafeModeShellContainerFactory.cs b/src/Orchard/Environment/ShellBuilders/SafeModeShellContainerFactory.cs index f8e5cc9ff..c1f63e07e 100644 --- a/src/Orchard/Environment/ShellBuilders/SafeModeShellContainerFactory.cs +++ b/src/Orchard/Environment/ShellBuilders/SafeModeShellContainerFactory.cs @@ -1,4 +1,6 @@ using System.Collections.Generic; +using System.Linq; +using System.Reflection; using System.Web; using System.Web.Mvc; using System.Web.Routing; @@ -58,10 +60,27 @@ namespace Orchard.Environment.ShellBuilders { builder.Register().As().ContainerScoped(); builder.Register().As().ContainerScoped(); + // yes, this is brutal, and if you are reading this, I sincerely appologize. + var dependencies = Assembly.Load("Orchard.Setup") + .GetExportedTypes() + .Where(type => type.IsClass && !type.IsAbstract && typeof(IDependency).IsAssignableFrom(type)); - //review: discovery an registration from limited number of modules (e.g. setup) should also be done here - //review: this should come from the limited number of added modules - builder.Register().As().ContainerScoped(); + foreach (var serviceType in dependencies) { + foreach (var interfaceType in serviceType.GetInterfaces()) { + if (typeof(IDependency).IsAssignableFrom(interfaceType)) { + var registrar = builder.Register(serviceType).As(interfaceType); + if (typeof(ISingletonDependency).IsAssignableFrom(interfaceType)) { + registrar.SingletonScoped(); + } + else if (typeof(ITransientDependency).IsAssignableFrom(interfaceType)) { + registrar.FactoryScoped(); + } + else { + registrar.ContainerScoped(); + } + } + } + } }); shellContainer.Build(builder => { @@ -73,26 +92,6 @@ namespace Orchard.Environment.ShellBuilders { return shellContainer; } - //review: this should come from the subset of modules, not this factory - class SetupRouteProvider : IRouteProvider { - public IEnumerable GetRoutes() { - var routes = new List(); - GetRoutes(routes); - return routes; - } - - public void GetRoutes(ICollection routes) { - routes.Add(new RouteDescriptor { - Priority = 100, - Route = new Route("{controller}/{action}", - new RouteValueDictionary { { "Area", "Orchard.Setup" }, { "Controller", "Setup" }, { "Action", "Index" } }, - new RouteValueDictionary { { "Area", "Orchard.Setup" }, { "Controller", "Setup" }, { "Action", "Index" } }, - new RouteValueDictionary { { "Area", "Orchard.Setup" } }, - new MvcRouteHandler()) - }); - } - } - class SafeModeText : IText { public LocalizedString Get(string textHint, params object[] args) { if (args == null || args.Length == 0) {