Skip to content

Commit

Permalink
Added strongly typed overloads of WithConstructorArgument which use a…
Browse files Browse the repository at this point in the history
… callback to get the value.
  • Loading branch information
Giorgi committed Oct 30, 2015
1 parent e09664f commit 5d7346b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Ninject/Planning/Bindings/BindingConfigurationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,11 @@ public IBindingWithOrOnSyntax<T> WithConstructorArgument(Type type, Func<IContex
return this.WithConstructorArgument(type, (context, target) => callback(context));
}

public IBindingWithOrOnSyntax<T> WithConstructorArgument<TValue>(Func<IContext, TValue> callback)
{
return this.WithConstructorArgument(typeof(TValue), (context, target) => callback(context));
}

/// <summary>
/// Indicates that the specified constructor argument should be overridden with the specified value.
/// </summary>
Expand All @@ -537,6 +542,12 @@ public IBindingWithOrOnSyntax<T> WithConstructorArgument(Type type, Func<IContex
return this;
}

public IBindingWithOrOnSyntax<T> WithConstructorArgument<TValue>(Func<IContext, ITarget, TValue> callback)
{
this.WithConstructorArgument(typeof (TValue), callback);
return this;
}

/// <summary>
/// Indicates that the specified property should be injected with the specified value.
/// </summary>
Expand Down
16 changes: 16 additions & 0 deletions src/Ninject/Syntax/IBindingWithSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ public interface IBindingWithSyntax<T> : IBindingSyntax
/// <returns>The fluent syntax.</returns>
IBindingWithOrOnSyntax<T> WithConstructorArgument(Type type, Func<IContext, object> callback);

/// <summary>
/// Indicates that the specified constructor argument should be overridden with the specified value.
/// </summary>
/// <typeparam name="TValue">Specifies the argument type to override.</typeparam>
/// <param name="callback">The callback to invoke to get the value for the argument.</param>
/// <returns>The fluent syntax.</returns>
IBindingWithOrOnSyntax<T> WithConstructorArgument<TValue>(Func<IContext, TValue> callback);

/// <summary>
/// Indicates that the specified constructor argument should be overridden with the specified value.
/// </summary>
Expand All @@ -91,6 +99,14 @@ public interface IBindingWithSyntax<T> : IBindingSyntax
/// <returns>The fluent syntax.</returns>
IBindingWithOrOnSyntax<T> WithConstructorArgument(Type type, Func<IContext, ITarget, object> callback);

/// <summary>
/// Indicates that the specified constructor argument should be overridden with the specified value.
/// </summary>
/// <typeparam name="TValue">Specifies the argument type to override.</typeparam>
/// <param name="callback">The callback to invoke to get the value for the argument.</param>
/// <returns>The fluent syntax.</returns>
IBindingWithOrOnSyntax<T> WithConstructorArgument<TValue>(Func<IContext, ITarget, TValue> callback);

/// <summary>
/// Indicates that the specified property should be injected with the specified value.
/// </summary>
Expand Down

0 comments on commit 5d7346b

Please sign in to comment.