mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Remove autofac workaround
We are now done with the integration of the new autofac, there is no need for these workaround anymore. --HG-- branch : dev
This commit is contained in:
@@ -12,12 +12,9 @@ namespace Orchard.Commands {
|
||||
if (!registration.Services.Contains(new TypedService(typeof(ICommandHandler))))
|
||||
return;
|
||||
|
||||
// Workaround autofac integration: module registration is currently run twice...
|
||||
if (!registration.Metadata.ContainsKey(typeof(CommandHandlerDescriptor).FullName)) {
|
||||
var builder = new CommandHandlerDescriptorBuilder();
|
||||
var descriptor = builder.Build(registration.Activator.LimitType);
|
||||
registration.Metadata.Add(typeof (CommandHandlerDescriptor).FullName, descriptor);
|
||||
}
|
||||
var builder = new CommandHandlerDescriptorBuilder();
|
||||
var descriptor = builder.Build(registration.Activator.LimitType);
|
||||
registration.Metadata.Add(typeof(CommandHandlerDescriptor).FullName, descriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -15,11 +15,8 @@ namespace Orchard.Commands {
|
||||
public void Execute(CommandParameters parameters) {
|
||||
var matches = MatchCommands(parameters);
|
||||
|
||||
// Workaround autofac integration: module registration is currently run twice...
|
||||
//if (matches.Count() == 1) {
|
||||
// var match = matches.Single();
|
||||
if (matches.Count() == 1 || matches.Count() == 2) {
|
||||
var match = matches.First();
|
||||
if (matches.Count() == 1) {
|
||||
var match = matches.Single();
|
||||
match.CommandHandlerFactory().Execute(match.Context);
|
||||
}
|
||||
else if (matches.Any()) {
|
||||
@@ -31,10 +28,7 @@ namespace Orchard.Commands {
|
||||
}
|
||||
|
||||
public IEnumerable<CommandDescriptor> GetCommandDescriptors() {
|
||||
return _handlers
|
||||
.SelectMany(h => GetDescriptor(h.Metadata).Commands)
|
||||
// Workaround autofac integration: module registration is currently run twice...
|
||||
.Distinct(new CommandsComparer());
|
||||
return _handlers.SelectMany(h => GetDescriptor(h.Metadata).Commands);
|
||||
}
|
||||
|
||||
private IEnumerable<Match> MatchCommands(CommandParameters parameters) {
|
||||
@@ -78,15 +72,5 @@ namespace Orchard.Commands {
|
||||
public CommandContext Context { get; set; }
|
||||
public Func<ICommandHandler> CommandHandlerFactory { get; set; }
|
||||
}
|
||||
|
||||
public class CommandsComparer : IEqualityComparer<CommandDescriptor> {
|
||||
public bool Equals(CommandDescriptor x, CommandDescriptor y) {
|
||||
return x.MethodInfo.Equals(y.MethodInfo);
|
||||
}
|
||||
|
||||
public int GetHashCode(CommandDescriptor obj) {
|
||||
return obj.MethodInfo.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user