Skip to content

Commit

Permalink
#44 Disposable Instances Handling - accumulator validating
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed Mar 27, 2024
1 parent cdaea6f commit ce81d7d
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/Pure.DI.Core/Core/MetadataValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ namespace Pure.DI.Core;

internal sealed class MetadataValidator(
ILogger<MetadataValidator> logger,
IBaseSymbolsProvider baseSymbolsProvider)
IBaseSymbolsProvider baseSymbolsProvider,
IMarker marker)
: IValidator<MdSetup>
{
public bool Validate(MdSetup setup)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ce81d7d

Please sign in to comment.