mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 20:13:50 +08:00
Adding Orchard.Setup dependencies when building safemode shell container
Enables routes and services in setup package to be used --HG-- branch : dev
This commit is contained in:
@@ -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"}
|
||||
},
|
||||
|
@@ -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<SafeModeText>().As<IText>().ContainerScoped();
|
||||
builder.Register<SafeModeSiteService>().As<ISiteService>().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<SetupRouteProvider>().As<IRouteProvider>().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<RouteDescriptor> GetRoutes() {
|
||||
var routes = new List<RouteDescriptor>();
|
||||
GetRoutes(routes);
|
||||
return routes;
|
||||
}
|
||||
|
||||
public void GetRoutes(ICollection<RouteDescriptor> 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) {
|
||||
|
Reference in New Issue
Block a user