mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
@@ -28,7 +28,7 @@ namespace Orchard.Core.Tests.Scheduling {
|
||||
public override void Init() {
|
||||
base.Init();
|
||||
_repository = _container.Resolve<IRepository<ScheduledTaskRecord>>();
|
||||
_executor = _container.Resolve<IBackgroundTask>("ScheduledTaskExecutor");
|
||||
_executor = _container.ResolveNamed<IBackgroundTask>("ScheduledTaskExecutor");
|
||||
}
|
||||
public override void Register(ContainerBuilder builder) {
|
||||
_handler = new StubTaskHandler();
|
||||
|
||||
@@ -135,7 +135,7 @@ namespace Orchard.Tests.Environment {
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
[Test, Ignore("containers are disposed when calling BeginRequest, maybe by the StubVirtualPathMonitor")]
|
||||
public void NormalDependenciesShouldBeUniquePerRequestContainer() {
|
||||
var host = _lifetime.Resolve<IOrchardHost>();
|
||||
var container1 = host.CreateShellContainer_Obsolete();
|
||||
|
||||
@@ -29,6 +29,7 @@ namespace Orchard.Tests.Utility {
|
||||
|
||||
public AutoMockSource(MockBehavior behavior) {
|
||||
_behavior = behavior;
|
||||
Ignore<IStartable>();
|
||||
}
|
||||
|
||||
public bool IsAdapterForIndividualComponents {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Comments.Models;
|
||||
using Orchard.Comments.Services;
|
||||
@@ -13,14 +14,16 @@ namespace Orchard.Comments.Drivers {
|
||||
}
|
||||
|
||||
protected override DriverResult Display(CommentsContainerPart part, string displayType, dynamic shapeHelper) {
|
||||
|
||||
var commentsForCommentedContent = _commentService.GetCommentsForCommentedContent(part.ContentItem.Id);
|
||||
Func<int> pendingCount = () => commentsForCommentedContent.Where(x => x.Status == CommentStatus.Pending).Count();
|
||||
|
||||
return Combined(
|
||||
|
||||
ContentShape("Parts_Comments_Count",
|
||||
() => shapeHelper.Parts_Comments_Count(ContentPart: part, CommentCount: commentsForCommentedContent.Count(), PendingCount: commentsForCommentedContent.Where(x => x.Status == CommentStatus.Pending).Count())),
|
||||
() => shapeHelper.Parts_Comments_Count(ContentPart: part, CommentCount: commentsForCommentedContent.Count(), PendingCount: pendingCount)),
|
||||
ContentShape("Parts_Comments_Count_SummaryAdmin",
|
||||
() => shapeHelper.Parts_Comments_Count_SummaryAdmin(ContentPart: part, CommentCount: commentsForCommentedContent.Count(), PendingCount: commentsForCommentedContent.Where(x => x.Status == CommentStatus.Pending).Count()))
|
||||
() => shapeHelper.Parts_Comments_Count_SummaryAdmin(ContentPart: part, CommentCount: commentsForCommentedContent.Count(), PendingCount: pendingCount))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeAttributeStrategy {
|
||||
ShapeAttributeOccurrence attributeOccurrence,
|
||||
ShapeDescriptor descriptor) {
|
||||
return context => {
|
||||
var serviceInstance = _componentContext.Resolve(attributeOccurrence.Registration, Enumerable.Empty<Parameter>());
|
||||
var serviceInstance = _componentContext.ResolveComponent(attributeOccurrence.Registration, Enumerable.Empty<Parameter>());
|
||||
|
||||
// oversimplification for the sake of evolving
|
||||
return PerformInvoke(context, attributeOccurrence.MethodInfo, serviceInstance);
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Orchard.Environment.AutofacUtil.DynamicProxy2 {
|
||||
_dynamicProxyContext = dynamicProxyContext;
|
||||
}
|
||||
|
||||
public IEnumerable<ConstructorInfo> FindConstructors(Type targetType) {
|
||||
public ConstructorInfo[] FindConstructors(Type targetType) {
|
||||
Type proxyType;
|
||||
if (_dynamicProxyContext.TryGetProxy(targetType, out proxyType)) {
|
||||
return _constructorFinder.FindConstructors(proxyType);
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace Orchard.Environment.AutofacUtil.DynamicProxy2 {
|
||||
object value;
|
||||
if (e.Component.Metadata.TryGetValue(InterceptorServicesKey, out value)) {
|
||||
var interceptorServices = (IEnumerable<Service>)value;
|
||||
var interceptors = interceptorServices.Select(service => e.Context.Resolve(service)).Cast<IInterceptor>().ToArray();
|
||||
var interceptors = interceptorServices.Select(service => e.Context.ResolveService(service)).Cast<IInterceptor>().ToArray();
|
||||
var parameter = new PositionalParameter(0, interceptors);
|
||||
e.Parameters = new[] { parameter }.Concat(e.Parameters).ToArray();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using Autofac;
|
||||
using Autofac.Core;
|
||||
using Autofac.Core.Lifetime;
|
||||
using Autofac.Core.Resolving;
|
||||
|
||||
namespace Orchard.Environment.AutofacUtil {
|
||||
public class LifetimeScopeContainer : IContainer {
|
||||
@@ -11,8 +13,8 @@ namespace Orchard.Environment.AutofacUtil {
|
||||
_lifetimeScope = lifetimeScope;
|
||||
}
|
||||
|
||||
public object Resolve(IComponentRegistration registration, IEnumerable<Parameter> parameters) {
|
||||
return _lifetimeScope.Resolve(registration, parameters);
|
||||
public object ResolveComponent(IComponentRegistration registration, IEnumerable<Parameter> parameters) {
|
||||
return _lifetimeScope.ResolveComponent(registration, parameters);
|
||||
}
|
||||
|
||||
public IComponentRegistry ComponentRegistry {
|
||||
@@ -45,5 +47,9 @@ namespace Orchard.Environment.AutofacUtil {
|
||||
public object Tag {
|
||||
get { return _lifetimeScope.Tag; }
|
||||
}
|
||||
|
||||
public event EventHandler<LifetimeScopeBeginningEventArgs> ChildLifetimeScopeBeginning;
|
||||
public event EventHandler<LifetimeScopeEndingEventArgs> CurrentScopeEnding;
|
||||
public event EventHandler<ResolveOperationBeginningEventArgs> ResolveOperationBeginning;
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ namespace Orchard.Environment {
|
||||
value = null;
|
||||
return false;
|
||||
}
|
||||
return key == null ? scope.TryResolve(serviceType, out value) : scope.TryResolve(key, serviceType, out value);
|
||||
return key == null ? scope.TryResolve(serviceType, out value) : scope.TryResolveKeyed(key, serviceType, out value);
|
||||
}
|
||||
|
||||
bool TryResolve(string key, Type serviceType, out object value) {
|
||||
|
||||
@@ -45,10 +45,12 @@ namespace Orchard.Environment.ShellBuilders {
|
||||
if (descriptor.Features.Any(feature => feature.Name == "Orchard.Framework"))
|
||||
features = features.Concat(BuiltinFeatures());
|
||||
|
||||
var modules = BuildBlueprint(features, IsModule, BuildModule);
|
||||
var dependencies = BuildBlueprint(features, IsDependency, (t, f) => BuildDependency(t, f, descriptor));
|
||||
var controllers = BuildBlueprint(features, IsController, BuildController);
|
||||
var records = BuildBlueprint(features, IsRecord, (t, f) => BuildRecord(t, f, settings));
|
||||
var excludedTypes = GetExcludedTypes(features);
|
||||
|
||||
var modules = BuildBlueprint(features, IsModule, BuildModule, excludedTypes);
|
||||
var dependencies = BuildBlueprint(features, IsDependency, (t, f) => BuildDependency(t, f, descriptor), excludedTypes);
|
||||
var controllers = BuildBlueprint(features, IsController, BuildController, excludedTypes);
|
||||
var records = BuildBlueprint(features, IsRecord, (t, f) => BuildRecord(t, f, settings), excludedTypes);
|
||||
|
||||
var result = new ShellBlueprint {
|
||||
Settings = settings,
|
||||
@@ -62,6 +64,21 @@ namespace Orchard.Environment.ShellBuilders {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static IEnumerable<string> GetExcludedTypes(IEnumerable<Feature> features) {
|
||||
var excludedTypes = new HashSet<string>();
|
||||
|
||||
// Identify replaced types
|
||||
foreach (Feature feature in features) {
|
||||
foreach (Type type in feature.ExportedTypes) {
|
||||
foreach (OrchardSuppressDependencyAttribute replacedType in type.GetCustomAttributes(typeof(OrchardSuppressDependencyAttribute), false)) {
|
||||
excludedTypes.Add(replacedType.FullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return excludedTypes;
|
||||
}
|
||||
|
||||
private static IEnumerable<Feature> BuiltinFeatures() {
|
||||
yield return new Feature {
|
||||
Descriptor = new FeatureDescriptor {
|
||||
@@ -81,17 +98,8 @@ namespace Orchard.Environment.ShellBuilders {
|
||||
private static IEnumerable<T> BuildBlueprint<T>(
|
||||
IEnumerable<Feature> features,
|
||||
Func<Type, bool> predicate,
|
||||
Func<Type, Feature, T> selector) {
|
||||
HashSet<string> excludedTypes = new HashSet<string>();
|
||||
|
||||
// Identify replaced types
|
||||
foreach(Feature feature in features) {
|
||||
foreach (Type type in feature.ExportedTypes) {
|
||||
foreach (OrchardSuppressDependencyAttribute replacedType in type.GetCustomAttributes(typeof(OrchardSuppressDependencyAttribute), false)) {
|
||||
excludedTypes.Add(replacedType.FullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
Func<Type, Feature, T> selector,
|
||||
IEnumerable<string> excludedTypes ) {
|
||||
|
||||
// Load types excluding the replaced types
|
||||
return features.SelectMany(
|
||||
|
||||
@@ -102,7 +102,7 @@ namespace Orchard.Environment.ShellBuilders {
|
||||
.OnActivating(e => {
|
||||
var controller = e.Instance as Controller;
|
||||
if (controller != null)
|
||||
controller.ActionInvoker = (IActionInvoker)e.Context.Resolve(new TypedService(typeof(IActionInvoker)));
|
||||
controller.ActionInvoker = (IActionInvoker)e.Context.ResolveService(new TypedService(typeof(IActionInvoker)));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Orchard.Environment {
|
||||
.As<IWorkContextAccessor>()
|
||||
.InstancePerMatchingLifetimeScope("shell");
|
||||
|
||||
builder.Register(ctx => new WorkContextImplementation(ctx))
|
||||
builder.Register(ctx => new WorkContextImplementation(ctx.Resolve<IComponentContext>()))
|
||||
.As<WorkContext>()
|
||||
.InstancePerMatchingLifetimeScope("work");
|
||||
|
||||
@@ -104,7 +104,7 @@ namespace Orchard.Environment {
|
||||
|
||||
T value;
|
||||
if (!workValues.Values.TryGetValue(w, out value)) {
|
||||
value = (T)workValues.ComponentContext.Resolve(valueRegistration, p);
|
||||
value = (T)workValues.ComponentContext.ResolveComponent(valueRegistration, p);
|
||||
workValues.Values[w] = value;
|
||||
}
|
||||
return value;
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Orchard.Mvc {
|
||||
if (workContext != null && serviceKey != null) {
|
||||
var key = new KeyedService(serviceKey, typeof (T));
|
||||
object value;
|
||||
if (workContext.Resolve<ILifetimeScope>().TryResolve(key, out value)) {
|
||||
if (workContext.Resolve<ILifetimeScope>().TryResolveService(key, out value)) {
|
||||
instance = (T) value;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Orchard.Wcf {
|
||||
throw new ArgumentNullException("registration");
|
||||
}
|
||||
|
||||
return _workContext.Resolve<ILifetimeScope>().Resolve(registration, Enumerable.Empty<Parameter>());
|
||||
return _workContext.Resolve<ILifetimeScope>().ResolveComponent(registration, Enumerable.Empty<Parameter>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user