ObjectFactory outdated.
You can exclude Decorator1<>from registration as vanilla ICommandHandler<>with the following code:
var container = new Container(config =>
{
config.Scan(scanner =>
{
scanner.AssemblyContainingType(typeof(ICommandHandler<>));
scanner.Exclude(t => t == typeof(Decorator1<>));
scanner.ConnectImplementationsToTypesClosing(typeof(ICommandHandler<>));
});
config.For(typeof(ICommandHandler<>)).DecorateAllWith(typeof(Decorator1<>));
});
UPDATE
DSL-
using StructureMap;
using StructureMap.Configuration.DSL;
public class CommandHandlerRegistry : Registry
{
public CommandHandlerRegistry()
{
Scan(scanner =>
{
scanner.AssemblyContainingType(typeof(ICommandHandler<>));
scanner.Exclude(t => t == typeof(Decorator1<>));
scanner.ConnectImplementationsToTypesClosing(typeof(ICommandHandler<>));
});
For(typeof(ICommandHandler<>)).DecorateAllWith(typeof(Decorator1<>));
}
}
Registry.
var container = new Container(config =>
{
config.AddRegistry<CommandHandlerRegistry>();
});
Registry ( )
var container = new Container(config =>
{
var registries = (
from assembly in AppDomain.CurrentDomain.GetAssemblies()
from type in assembly.DefinedTypes
where typeof(Registry).IsAssignableFrom(type)
where !type.IsAbstract
where !type.Namespace.StartsWith("StructureMap")
select Activator.CreateInstance(type))
.Cast<Registry>();
foreach (var registry in registries)
{
config.AddRegistry(registry);
}
});