@@ -15,7 +15,7 @@ public class TemplateConstraintManager : IDisposable
15
15
private readonly ILogger < TemplateConstraintManager > _logger ;
16
16
private readonly CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource ( ) ;
17
17
private readonly Dictionary < string , ITemplateConstraint > _templateConstraints = new ( ) ;
18
- private readonly Dictionary < string , TemplateConstraintResult > _evaluatedConstraints = new ( ) ;
18
+ private readonly Dictionary < ( string Type , string ? Args ) , TemplateConstraintResult > _evaluatedConstraints = new ( ) ;
19
19
20
20
public TemplateConstraintManager ( IEngineEnvironmentSettings engineEnvironmentSettings )
21
21
{
@@ -58,21 +58,26 @@ public async Task<IReadOnlyList<ITemplateConstraint>> GetConstraintsAsync(IEnume
58
58
public async Task < TemplateConstraintResult > EvaluateConstraintAsync ( string type , string ? args , CancellationToken cancellationToken )
59
59
{
60
60
cancellationToken . ThrowIfCancellationRequested ( ) ;
61
- if ( _evaluatedConstraints . TryGetValue ( type , out TemplateConstraintResult result ) )
61
+ if ( _evaluatedConstraints . TryGetValue ( ( type , args ) , out TemplateConstraintResult result ) )
62
62
{
63
63
return result ;
64
64
}
65
65
66
66
if ( ! _templateConstraints . TryGetValue ( type , out ITemplateConstraint constraint ) )
67
67
{
68
+ if ( _evaluatedConstraints . TryGetValue ( ( type , null ) , out result ) )
69
+ {
70
+ return result ;
71
+ }
72
+
68
73
_logger . LogDebug ( $ "The constraint '{ type } ' is unknown.") ;
69
74
return TemplateConstraintResult . CreateInitializationFailure ( type , string . Format ( LocalizableStrings . TemplateConstraintManager_Error_UnknownType , type ) ) ;
70
75
}
71
76
72
77
try
73
78
{
74
79
result = constraint . Evaluate ( args ) ;
75
- _evaluatedConstraints . Add ( type , result ) ;
80
+ _evaluatedConstraints . Add ( ( type , args ) , result ) ;
76
81
return result ;
77
82
}
78
83
catch ( Exception e )
@@ -159,7 +164,7 @@ private async Task InitializeTemplateConstraints(IEngineEnvironmentSettings engi
159
164
{
160
165
exception = exception is not null ? exception . InnerException ?? exception : exception ;
161
166
_logger . LogDebug ( $ "The constraint '{ constraintFactory . Type } ' failed to be initialized, details: { exception } .") ;
162
- _evaluatedConstraints . Add ( constraintFactory . Type , TemplateConstraintResult . CreateInitializationFailure ( constraintFactory . Type , string . Format ( LocalizableStrings . TemplateConstraintManager_Error_FailedToInitialize , constraintFactory . Type , exception ? . Message ) ) ) ;
167
+ _evaluatedConstraints . Add ( ( constraintFactory . Type , null ) , TemplateConstraintResult . CreateInitializationFailure ( constraintFactory . Type , string . Format ( LocalizableStrings . TemplateConstraintManager_Error_FailedToInitialize , constraintFactory . Type , exception ? . Message ) ) ) ;
163
168
}
164
169
else
165
170
{
0 commit comments