Skip to content

Commit 087dfa1

Browse files
committed
added check for null argument in NamedLikeFactoryMethod syntax extension method
1 parent b9d0b65 commit 087dfa1

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/Ninject.Extensions.Factory.Test/FactoryTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ public void NamedLikeFactoryMethodThrowsExceptionWhenNotAGetFactoryMethod()
101101
action.ShouldThrow<ArgumentException>();
102102
}
103103

104+
[Fact]
105+
public void NamedLikeFactoryMethodThrowsExceptionWhenActionIsNull()
106+
{
107+
Action action = () => this.kernel.Bind<IWeapon>().To<Sword>().NamedLikeFactoryMethod<Sword, ICustomizableWeapon>(null);
108+
109+
action.ShouldThrow<ArgumentNullException>();
110+
}
111+
104112
[Fact]
105113
public void GetFallback()
106114
{

src/Ninject.Extensions.Factory/BindToExtensions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ public static IBindingWhenInNamedWithOrOnSyntax<object> ToFactory(this IBindingT
100100
/// </returns>
101101
public static IBindingWithOrOnSyntax<TInterface> NamedLikeFactoryMethod<TInterface, TFactory>(this IBindingNamedSyntax<TInterface> syntax, Expression<Action<TFactory>> action)
102102
{
103+
if (action == null)
104+
{
105+
throw new ArgumentNullException("action");
106+
}
107+
103108
var methodCallExpression = action.Body as MethodCallExpression;
104109

105110
if (methodCallExpression == null)

0 commit comments

Comments
 (0)