public ConstantBindingContainer( BindingContainerTypes types, ArgumentSyntax constantSyntax, BindScopeEnum scope, ExpressionStatementSyntax expressionNode, ArgumentSyntax?whenArgumentClause, IReadOnlyList <IDefinedSetting> settings ) : base(types, scope, expressionNode, whenArgumentClause, constantSyntax, settings, false) { ConstructorArguments = new List <DetectedMethodArgument>(); }
public ConstantBindingContainer( IReadOnlyList <ITypeSymbol> bindFromTypes, ITypeSymbol constTypeSymbol, ArgumentSyntax constantSyntax, BindScopeEnum scope, ArgumentSyntax?whenArgumentClause ) : base(bindFromTypes, constTypeSymbol, scope, whenArgumentClause, constantSyntax, null) { ConstructorArguments = new List <DetectedConstructorArgument>(); NotBindConstructorArgumentTypes = new HashSet <ITypeSymbol>(); }
public BindingContainerWithInstance( BindingContainerTypes types, IReadOnlyList <DetectedMethodArgument> constructorArguments, BindScopeEnum scope, ExpressionStatementSyntax expressionNode, ArgumentSyntax?whenArgumentClause, IReadOnlyList <IDefinedSetting> settings, bool isConventional ) : base(types, scope, expressionNode, whenArgumentClause, null, settings, isConventional) { if (constructorArguments is null) { throw new ArgumentNullException(nameof(constructorArguments)); } ConstructorArguments = constructorArguments; }
protected BaseBindingContainer( BindingContainerTypes types, BindScopeEnum scope, ExpressionStatementSyntax expressionNode, ArgumentSyntax?whenArgumentClause, ArgumentSyntax?constantSyntax, IReadOnlyList <IDefinedSetting> settings, bool isConventional ) { if (types is null) { throw new ArgumentNullException(nameof(types)); } if (scope == BindScopeEnum.Constant && constantSyntax is null) { throw new DpdtException(DpdtExceptionTypeEnum.InternalError, $"Misconfiguration between scope and constant syntax"); } if (settings is null) { throw new ArgumentNullException(nameof(settings)); } if (scope != BindScopeEnum.Constant && !(constantSyntax is null)) { throw new DpdtException(DpdtExceptionTypeEnum.InternalError, $"Misconfiguration between scope and constant syntax"); } _types = types; Scope = scope; ExpressionNode = expressionNode; WhenArgumentClause = whenArgumentClause; ConstantSyntax = constantSyntax; _settings = settings; IsConventional = isConventional; UniqueUnstableIdentifier = Guid.NewGuid(); var uniqueKey0 = expressionNode.SyntaxTree.FilePath.GetStringSha256Hash().SafeSubstring(0, 8); var uniqueKey1 = expressionNode.Span.Start; var uniqueKey2 = expressionNode.Span.End; var uniqueKey3 = types.BindToType.ToGlobalDisplayString().GetStringSha256Hash().SafeSubstring(0, 8); _uniqueKey = $"u{uniqueKey0}_{uniqueKey1}_{uniqueKey2}_{uniqueKey3}"; }
public BindingContainerWithInstance( IReadOnlyList <ITypeSymbol> bindFromTypes, ITypeSymbol bindToType, IReadOnlyList <DetectedConstructorArgument> constructorArguments, BindScopeEnum scope, ArgumentSyntax?whenArgumentClause, ITypeSymbol?factoryPayloadType ) : base(bindFromTypes, bindToType, scope, whenArgumentClause, null, factoryPayloadType) { if (constructorArguments is null) { throw new ArgumentNullException(nameof(constructorArguments)); } ConstructorArguments = constructorArguments; NotBindConstructorArgumentTypes = new HashSet <ITypeSymbol>( constructorArguments .Where(ca => !ca.DefineInBindNode) .Select(ca => ca.Type !), new TypeSymbolEqualityComparer() ); }
public NewBindingInfo( IReadOnlyCollection <INamedTypeSymbol> bindFroms, INamedTypeSymbol bindTo, IMethodSymbol constructor, List <IParameterSymbol> manualConstructorArguments, ConstructorSettingsEnum constructorSetting, BindScopeEnum bindScope, bool isConditional ) { if (bindFroms is null) { throw new ArgumentNullException(nameof(bindFroms)); } if (bindTo is null) { throw new ArgumentNullException(nameof(bindTo)); } if (constructor is null) { throw new ArgumentNullException(nameof(constructor)); } if (manualConstructorArguments is null) { throw new ArgumentNullException(nameof(manualConstructorArguments)); } BindFroms = bindFroms; BindTo = bindTo; Constructor = constructor; ManualConstructorArguments = manualConstructorArguments; ConstructorSetting = constructorSetting; BindScope = bindScope; IsConditional = isConditional; }
public bool IsAllowedFor(BindScopeEnum scope) => scope.In(BindScopeEnum.Singleton, BindScopeEnum.Transient, BindScopeEnum.Custom);
public bool IsAllowedFor(BindScopeEnum scope) => true;
public BaseParsedBindExpression( BindScopeEnum scope, List <Tuple <InvocationExpressionSyntax, IMethodSymbol> > invocationSymbols ) { if (invocationSymbols is null) { throw new ArgumentNullException(nameof(invocationSymbols)); } _scope = scope; var settingScopes = new HashSet <string>(); var setupInvocations = invocationSymbols.FindAll(p => p.Item2.Name == nameof(IConfigureAndConditionalBinding.Setup)); foreach (var setupInvocation in setupInvocations) { var settingSymbol = (INamedTypeSymbol)setupInvocation.Item2.TypeArguments.First(); IDefinedSetting setting; if (settingSymbol.BaseType != null && settingSymbol.BaseType.ToDisplayString() == typeof(AllAndOrderConstructorSetting).FullName) { var constructorSetting = new ConstructorSetting(ConstructorSettingsEnum.AllAndOrder); constructorSetting.AddRange( settingSymbol.TypeArguments ); setting = constructorSetting; } else if (settingSymbol.BaseType != null && settingSymbol.BaseType.ToDisplayString() == typeof(SubsetAndOrderConstructorSetting).FullName) { var constructorSetting = new ConstructorSetting(ConstructorSettingsEnum.SubsetAndOrder); constructorSetting.AddRange( settingSymbol.TypeArguments ); setting = constructorSetting; } else if (settingSymbol.BaseType != null && settingSymbol.BaseType.ToDisplayString() == typeof(SubsetNoOrderConstructorSetting).FullName) { var constructorSetting = new ConstructorSetting(ConstructorSettingsEnum.SubsetNoOrder); constructorSetting.AddRange( settingSymbol.TypeArguments ); setting = constructorSetting; } else if (settingSymbol.ToDisplayString() == typeof(PerformCircularCheck).FullName) { setting = new CircularSetting(true); } else if (settingSymbol.ToDisplayString() == typeof(SuppressCircularCheck).FullName) { setting = new CircularSetting(false); } else if (settingSymbol.ToDisplayString() == typeof(AllowedCrossCluster).FullName) { setting = new CrossClusterSetting(CrossClusterSettingEnum.AllowedCrossCluster); } else if (settingSymbol.ToDisplayString() == typeof(MustBeCrossCluster).FullName) { setting = new CrossClusterSetting(CrossClusterSettingEnum.MustBeCrossCluster); } else if (settingSymbol.ToDisplayString() == typeof(OnlyLocalCluster).FullName) { setting = new CrossClusterSetting(CrossClusterSettingEnum.OnlyLocal); } else if (settingSymbol.ToDisplayString() == typeof(NoWrappers).FullName) { setting = new WrapperSetting(false); } else if (settingSymbol.ToDisplayString() == typeof(ProduceWrappers).FullName) { setting = new WrapperSetting(true); } else { throw new DpdtException( DpdtExceptionTypeEnum.IncorrectBinding_IncorrectSetting, $"Incorrect setting used [{settingSymbol.ToGlobalDisplayString()}]", settingSymbol.ToGlobalDisplayString() ); } if (settingScopes.Contains(setting.Scope)) { throw new DpdtException( DpdtExceptionTypeEnum.IncorrectBinding_IncorrectSetting, $"Only one settings of each scope is allowed [{setting.Scope}]", settingSymbol.ToGlobalDisplayString() ); } settingScopes.Add(setting.Scope); if (!setting.IsAllowedFor(scope)) { throw new DpdtException( DpdtExceptionTypeEnum.IncorrectBinding_IncorrectSetting, $"Setting {setting.GetType().Name} is incompatible with scope {scope}" ); } _settings.Add(setting); } }
public override async Task StartAsync() { _scope = _choosedParameters.Scope; IsConditionalBinding = _choosedParameters.IsConditionalBinding; }