Skip to content

Commit

Permalink
Merge branch '4.0.0' of https://github.com/iappert/ninject into 4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
iappert committed Apr 25, 2014
2 parents 17b83af + d118f7c commit 795f186
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
13 changes: 9 additions & 4 deletions src/Ninject/Planning/Directives/ConstructorInjectionDirective.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ namespace Ninject.Planning.Directives
/// Describes the injection of a constructor.
/// </summary>
public class ConstructorInjectionDirective : MethodInjectionDirectiveBase<ConstructorInfo, ConstructorInjector>
{
{
/// <summary>
/// The base .ctor definition.
/// </summary>
public ConstructorInfo Constructor { get; set; }

public ConstructorInfo Constructor { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the <see cref="Constructor"/> has inject attribute.
/// </summary>
public bool HasInjectAttribute { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="ConstructorInjectionDirective"/> class.
/// </summary>
Expand All @@ -35,6 +40,6 @@ public ConstructorInjectionDirective(ConstructorInfo constructor, ConstructorInj
: base(constructor, injector)
{
Constructor = constructor;
}
}
}
}
16 changes: 12 additions & 4 deletions src/Ninject/Planning/Strategies/ConstructorReflectionStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
#endregion

namespace Ninject.Planning.Strategies
{
{
using Ninject.Infrastructure.Language;

/// <summary>
/// Adds a directive to plans indicating which constructor should be injected during activation.
/// </summary>
Expand Down Expand Up @@ -57,9 +59,15 @@ public void Execute(IPlan plan)
if(constructors == null)
return;

foreach(ConstructorInfo constructor in constructors)
{
plan.Add(new ConstructorInjectionDirective(constructor, InjectorFactory.Create(constructor)));
foreach(ConstructorInfo constructor in constructors)
{
bool hasInjectAttribute = constructor.HasAttribute(Settings.InjectAttribute);
var directive = new ConstructorInjectionDirective(constructor, InjectorFactory.Create(constructor))
{
HasInjectAttribute = hasInjectAttribute
};

plan.Add(directive);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class StandardConstructorScorer : NinjectComponent, IConstructorScorer
/// <returns>The constructor's score.</returns>
public virtual int Score(IContext context, ConstructorInjectionDirective directive)
{
if (directive.Constructor.HasAttribute(Settings.InjectAttribute))
if (directive.HasInjectAttribute)
{
return int.MaxValue;
}
Expand Down

0 comments on commit 795f186

Please sign in to comment.