From ce81d7d3ad74c2b83f4733e1c36d38f4810c0c77 Mon Sep 17 00:00:00 2001 From: Nikolay Pianikov Date: Wed, 27 Mar 2024 12:00:41 +0300 Subject: [PATCH] #44 Disposable Instances Handling - accumulator validating --- src/Pure.DI.Core/Core/MetadataValidator.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Pure.DI.Core/Core/MetadataValidator.cs b/src/Pure.DI.Core/Core/MetadataValidator.cs index 1ef8f49a8..77aabf039 100644 --- a/src/Pure.DI.Core/Core/MetadataValidator.cs +++ b/src/Pure.DI.Core/Core/MetadataValidator.cs @@ -5,7 +5,8 @@ namespace Pure.DI.Core; internal sealed class MetadataValidator( ILogger logger, - IBaseSymbolsProvider baseSymbolsProvider) + IBaseSymbolsProvider baseSymbolsProvider, + IMarker marker) : IValidator { public bool Validate(MdSetup setup) @@ -54,11 +55,24 @@ public bool Validate(MdSetup setup) foreach (var root in roots.Skip(1)) { - logger.CompileError($"The composition root \"{root.Name}\" duplicates the previously declared root \"{roots[0].Name}\"", root.Source.GetLocation(), LogId.ErrorInvalidMetadata); + logger.CompileError($"The composition root \"{root.Name}\" duplicates the previously declared root \"{roots[0].Name}\".", root.Source.GetLocation(), LogId.ErrorInvalidMetadata); isValid = false; } } + foreach (var accumulator in setup.Accumulators) + { + if (marker.IsMarkerBased(accumulator.AccumulatorType)) + { + logger.CompileError("Accumulator based on marker type is not supported.", accumulator.Source.GetLocation(), LogId.ErrorInvalidMetadata); + } + + if (marker.IsMarkerBased(accumulator.Type)) + { + logger.CompileError("The accumulator cannot accumulate instances based on marker type.", accumulator.Source.GetLocation(), LogId.ErrorInvalidMetadata); + } + } + if (!isValid) { throw HandledException.Shared;