mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-01-18 19:51:45 +08:00
#17830: Registering ServiceRoutes after MVCRoutes. Using existing WorkContext in OrchardFactory in case of aspnetcompatibilitymode.
--HG-- branch : 1.x
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.ServiceModel.Activation;
|
||||||
using System.Web.Routing;
|
using System.Web.Routing;
|
||||||
using Autofac;
|
using Autofac;
|
||||||
using Orchard.Environment;
|
using Orchard.Environment;
|
||||||
@@ -24,7 +25,10 @@ namespace Orchard.Mvc.Routes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void Publish(IEnumerable<RouteDescriptor> routes) {
|
public void Publish(IEnumerable<RouteDescriptor> routes) {
|
||||||
var routesArray = routes.OrderByDescending(r => r.Priority).ToArray();
|
var routesArray = routes
|
||||||
|
.OrderByDescending(r => r.Route is ServiceRoute ? -1 : 1)
|
||||||
|
.ThenByDescending(r => r.Priority)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
// this is not called often, but is intended to surface problems before
|
// this is not called often, but is intended to surface problems before
|
||||||
// the actual collection is modified
|
// the actual collection is modified
|
||||||
|
|||||||
@@ -7,9 +7,15 @@ using Autofac.Core;
|
|||||||
namespace Orchard.Wcf {
|
namespace Orchard.Wcf {
|
||||||
public class OrchardInstanceContext : IExtension<InstanceContext>, IDisposable {
|
public class OrchardInstanceContext : IExtension<InstanceContext>, IDisposable {
|
||||||
private readonly IWorkContextScope _workContextScope;
|
private readonly IWorkContextScope _workContextScope;
|
||||||
|
private readonly WorkContext _workContext;
|
||||||
|
|
||||||
public OrchardInstanceContext(IWorkContextAccessor workContextAccessor) {
|
public OrchardInstanceContext(IWorkContextAccessor workContextAccessor) {
|
||||||
_workContextScope = workContextAccessor.CreateWorkContextScope();
|
_workContext = workContextAccessor.GetContext();
|
||||||
|
|
||||||
|
if (_workContext == null) {
|
||||||
|
_workContextScope = workContextAccessor.CreateWorkContextScope();
|
||||||
|
_workContext = _workContextScope.WorkContext;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Attach(InstanceContext owner) {}
|
public void Attach(InstanceContext owner) {}
|
||||||
@@ -17,7 +23,9 @@ namespace Orchard.Wcf {
|
|||||||
public void Detach(InstanceContext owner) {}
|
public void Detach(InstanceContext owner) {}
|
||||||
|
|
||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
_workContextScope.Dispose();
|
if (_workContextScope != null) {
|
||||||
|
_workContextScope.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public object Resolve(IComponentRegistration registration) {
|
public object Resolve(IComponentRegistration registration) {
|
||||||
@@ -25,7 +33,7 @@ namespace Orchard.Wcf {
|
|||||||
throw new ArgumentNullException("registration");
|
throw new ArgumentNullException("registration");
|
||||||
}
|
}
|
||||||
|
|
||||||
return _workContextScope.Resolve<ILifetimeScope>().Resolve(registration, Enumerable.Empty<Parameter>());
|
return _workContext.Resolve<ILifetimeScope>().Resolve(registration, Enumerable.Empty<Parameter>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,17 +37,17 @@ namespace Orchard.Wcf {
|
|||||||
IOrchardHost orchardHost = HostContainer.Resolve<IOrchardHost>();
|
IOrchardHost orchardHost = HostContainer.Resolve<IOrchardHost>();
|
||||||
ShellContext shellContext = orchardHost.GetShellContext(shellSettings);
|
ShellContext shellContext = orchardHost.GetShellContext(shellSettings);
|
||||||
IWorkContextAccessor workContextAccessor = shellContext.LifetimeScope.Resolve<IWorkContextAccessor>();
|
IWorkContextAccessor workContextAccessor = shellContext.LifetimeScope.Resolve<IWorkContextAccessor>();
|
||||||
|
WorkContext workContext = workContextAccessor.GetContext();
|
||||||
using (IWorkContextScope workContext = workContextAccessor.CreateWorkContextScope()) {
|
if (workContext == null) {
|
||||||
|
using (IWorkContextScope workContextScope = workContextAccessor.CreateWorkContextScope()) {
|
||||||
ILifetimeScope lifetimeScope = workContext.Resolve<ILifetimeScope>();
|
ILifetimeScope lifetimeScope = workContextScope.Resolve<ILifetimeScope>();
|
||||||
if (!lifetimeScope.ComponentRegistry.TryGetRegistration(new KeyedService(constructorString, typeof (object)), out registration)) {
|
registration = GetRegistration(lifetimeScope, constructorString);
|
||||||
Type serviceType = Type.GetType(constructorString, false);
|
|
||||||
if (serviceType != null) {
|
|
||||||
lifetimeScope.ComponentRegistry.TryGetRegistration(new TypedService(serviceType), out registration);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
ILifetimeScope lifetimeScope = workContext.Resolve<ILifetimeScope>();
|
||||||
|
registration = GetRegistration(lifetimeScope, constructorString);
|
||||||
|
}
|
||||||
|
|
||||||
if (registration == null) {
|
if (registration == null) {
|
||||||
throw new InvalidOperationException();
|
throw new InvalidOperationException();
|
||||||
@@ -69,5 +69,17 @@ namespace Orchard.Wcf {
|
|||||||
|
|
||||||
return host;
|
return host;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IComponentRegistration GetRegistration(ILifetimeScope lifetimeScope, string constructorString) {
|
||||||
|
IComponentRegistration registration;
|
||||||
|
if (!lifetimeScope.ComponentRegistry.TryGetRegistration(new KeyedService(constructorString, typeof(object)), out registration)) {
|
||||||
|
Type serviceType = Type.GetType(constructorString, false);
|
||||||
|
if (serviceType != null) {
|
||||||
|
lifetimeScope.ComponentRegistry.TryGetRegistration(new TypedService(serviceType), out registration);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return registration;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user