diff --git a/CoRProcessor/CoRProcessor.cs b/CoRProcessor/CoRProcessor.cs index 9fc754f..10c53eb 100644 --- a/CoRProcessor/CoRProcessor.cs +++ b/CoRProcessor/CoRProcessor.cs @@ -38,7 +38,6 @@ public CoRProcessor AddRange(IEnumerable> processors) public async Task Execute(T t, CancellationToken token = default) { - _chainProcessors.Add(new EmptyProcessor()); _firstHandler = BuildChain(_chainProcessors.DistinctBy(x => x.GetType()).ToList()); try @@ -95,10 +94,12 @@ public CoRProcessor OnException(FuncDelegate action) return this; } - private IChainProcessor BuildChain(IReadOnlyList> processors) + private IChainProcessor BuildChain(List> processors) { if (processors.Count == 0) throw new Exception("No processors provided. At least one processor is required."); + + processors.Add(new EmptyProcessor()); for (var i = 0; i < processors.Count - 1; i++) { diff --git a/CoRProcessor/SetupCor.cs b/CoRProcessor/SetupCor.cs index 39a675b..9f8145b 100644 --- a/CoRProcessor/SetupCor.cs +++ b/CoRProcessor/SetupCor.cs @@ -13,10 +13,7 @@ public static IServiceCollection AddCoR(this IServiceCollection services, Assemb foreach (var type in assembly.GetTypes() .Where(t => IsAssignableToGenericType(t, typeof(IChainProcessor<>)) && t.IsClass)) { - if (type.GetGenericArguments().Length > 0) - { - continue; - } + if (type.GetGenericArguments().Length > 0) continue; services.AddScoped(type); } @@ -28,10 +25,7 @@ public static ContainerBuilder AddCoR(this ContainerBuilder containerBuilder, As foreach (var type in assembly.GetTypes() .Where(t => IsAssignableToGenericType(t, typeof(IChainProcessor<>)) && t.IsClass)) { - if (type.GetGenericArguments().Length > 0) - { - continue; - } + if (type.GetGenericArguments().Length > 0) continue; containerBuilder.RegisterType(type).AsSelf().AsImplementedInterfaces().InstancePerLifetimeScope(); } diff --git a/UnitTests/UnitTests.cs b/UnitTests/UnitTests.cs index 7428c77..fd424aa 100644 --- a/UnitTests/UnitTests.cs +++ b/UnitTests/UnitTests.cs @@ -218,4 +218,22 @@ public async Task TestCorProcessorRunningOnAutofac() Assert.That(result.Result, Is.EqualTo(2)); } + + + [Test] + public async Task TestEmptyProcessorRunning() + { + var emptyProcessor = new EmptyProcessor(); + emptyProcessor.Next = new AdditionProcessor(); + + var result = await emptyProcessor.Handle(new NumberContext() + { + Number1 = 1, + Number2 = 2, + Operation = Operation.Addition + }, default); + + Assert.That(result.Result, Is.EqualTo(0)); + Assert.That(emptyProcessor.Next.GetType().FullName, Is.EqualTo(typeof(AdditionProcessor).FullName)); + } } \ No newline at end of file