public static IBindingInNamedWithOrOnSyntax <object> WhenNotificationMatchesType <TNotification>( this IBindingWhenSyntax <object> syntax) where TNotification : INotification { return(syntax.When(request => typeof(TNotification).IsAssignableFrom(request.Service.GenericTypeArguments.Single()))); }
// note: May be done better to check Request constraints, but for sample is fine public static IBindingInNamedWithOrOnSyntax <object> WhenNotificationMatchesType( this IBindingWhenSyntax <object> syntax, params Type[][] typeArgsVariants) => syntax.When(request => { var typeArgs = request.Service.GenericTypeArguments; return(typeArgsVariants.Any(closedTypeArgs => closedTypeArgs.Select((t, i) => t.IsAssignableFrom(typeArgs[i])).All(id => id))); });
/// <summary> /// Condition that matches when the target has the given name. /// </summary> /// <typeparam name="T">The type of the binding.</typeparam> /// <param name="syntax">The syntax.</param> /// <param name="name">The name.</param> /// <returns>The syntax to define more things for the binding.</returns> public static IBindingInNamedWithOrOnSyntax <T> WhenTargetNamed <T>(this IBindingWhenSyntax <T> syntax, string name) { return(syntax.When( request => request.Target != null && request.Target.Name.ToUpper(CultureInfo.InvariantCulture) == name.ToUpper(CultureInfo.InvariantCulture))); }
public static IBindingInNamedWithOrOnSyntax <T> WhenInjectedInto <T>( this IBindingWhenSyntax <T> syntax, Type parentType, string name) { var condition = ComputeMatchCondition <T>(syntax, parentType); return(syntax.When(request => condition(request) && request.ActiveBindings.Any(b => b.Metadata.Name == name))); }
public static IBindingInNamedWithOrOnSyntax <T> WhenInjectedInto <T> ( this IBindingWhenSyntax <T> syntax, params Type[] types ) { var conditions = ComputeMatchConditions(syntax, types).ToArray(); return(syntax.When(request => conditions.Any(condition => condition(request)))); }
public static IBindingInNamedWithOrOnSyntax <T> WhenFileCode <T>( this IBindingWhenSyntax <T> syntax, FileCode fileCode) { return(syntax.When(req => req .Parameters .OfType <FileCodeParameter>() .Single() .FileCode.Value == fileCode.Value)); }
/// <summary> /// Specifies that the binding should be considered only when injecting into a constructor parameter with the given name. /// </summary> /// <typeparam name="T">The service type.</typeparam> /// <param name="builder">The fluent syntax.</param> /// <param name="parameterName">The name of the constructor parameter.</param> /// <returns>The fluent syntax.</returns> public static IBindingInNamedWithOrOnSyntax <T> InjectedIntoParameter <T>(this IBindingWhenSyntax <T> builder, string parameterName) { return(ProfilerInterceptor.GuardInternal(() => { return builder.When(req => { var target = req.Target as ParameterTarget; return req.Target == null || target != null && target.Site.Name == parameterName; }); })); }
/// <summary> /// Specifies that the binding should be considered only when injecting into the given property. /// </summary> /// <typeparam name="T">The service type.</typeparam> /// <typeparam name="TTarget">The type defining the property.</typeparam> /// <typeparam name="TProperty">The type of the property.</typeparam> /// <param name="builder">The fluent syntax.</param> /// <param name="propertyExpr">An expression referencing the property, e.g. <code>(TransactionService s) => s.CreditCardService</code></param> /// <returns>The fluent syntax.</returns> public static IBindingInNamedWithOrOnSyntax <T> InjectedIntoProperty <T, TTarget, TProperty>(this IBindingWhenSyntax <T> builder, Expression <Func <TTarget, TProperty> > propertyExpr) { return(ProfilerInterceptor.GuardInternal(() => { MemberInfo member = ((MemberExpression)propertyExpr.Body).Member; if (!(member is PropertyInfo)) { throw new ArgumentException("Expression should represent a property. Note that field injection is not supported."); } return builder.When(req => { var target = req.Target as PropertyTarget; return req.Target == null || target != null && target.Site == member; }); })); }
public static IBindingInNamedWithOrOnSyntax <T> WhenClassifiedBy <T>(this IBindingWhenSyntax <T> syntax, string classification) { return(syntax.When(request => request.IsValidForClassification(classification))); }
public static IBindingInNamedWithOrOnSyntax <T> WhenNoAnchestorNamed <T>(this IBindingWhenSyntax <T> syntax, string name) { return(syntax.When(r => !IsAnyAnchestorNamed(r, name))); }
public static IBindingInNamedWithOrOnSyntax <object> WhenEntityMatchesType <TEntityType>( this IBindingWhenSyntax <object> syntax) { return(syntax.When(request => DoesEntityMatchType(request, typeof(TEntityType)))); }
public static IBindingInNamedWithOrOnSyntax <T> MakePreferredBinding <T>( this IBindingWhenSyntax <T> syntax) { return(syntax.When(req => true)); }
public static IBindingInNamedWithOrOnSyntax <T> WhenIsDescendantOf <T>(this IBindingWhenSyntax <T> syntax, Type ancestor) { return(syntax.When(request => request.ActiveBindings.Any(p => p.Service.Name == ancestor.Name))); }
/// <summary> /// Indicates that the binding should be used only for requests that support the specified condition. /// </summary> /// <typeparam name="T">The type used in the binding.</typeparam> /// <param name="whenSyntax">The when syntax.</param> /// <param name="condition">The condition.</param> /// <returns>The syntax</returns> public static IBindingInNamedWithOrOnSyntax <T> WhenInjectedIntoActivity <T>(this IBindingWhenSyntax <T> whenSyntax, Func <Activity, bool> condition) { return(whenSyntax.When(request => request.HasRootActivityParameter() && condition(request.GetRootActivityParameter().Root))); }
public static IBindingInNamedWithOrOnSyntax <object> WhenSignalMatchesType <TSignal>(this IBindingWhenSyntax <object> syntax) where TSignal : ISignal { return(syntax.When(request => typeof(TSignal).IsAssignableFrom(request.Service.GenericTypeArguments.Single()))); }
public static IBindingInNamedWithOrOnSyntax <T> WhenInjectedIntoDescendentOf <T>(this IBindingWhenSyntax <T> when, Type ancestor) { return(when.When(r => IsTypeRequestedByAncestor(r, ancestor))); }
public static IBindingInNamedWithOrOnSyntax <T> WhenInCurrentTest <T>(this IBindingWhenSyntax <T> binding) { var testName = TestContext.CurrentContext.Test.FullName; return(binding.When(w => TestContext.CurrentContext.Test.FullName == testName)); }