Skip to content

Commit 2646ba8

Browse files
committed
Fixed #38
1 parent daaf542 commit 2646ba8

File tree

7 files changed

+65
-13
lines changed

7 files changed

+65
-13
lines changed

appveyor.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,18 @@ cache:
2525
- '%LocalAppData%\NuGet\v3-cache -> **\*.csproj'
2626

2727
before_build:
28-
- nuget restore -Verbosity quiet
28+
- dotnet restore --verbosity quiet
2929
- choco install opencover.portable
3030
- choco install codecov
3131

3232
build:
33+
parallel: true
3334
verbosity: minimal
3435

3536
test_script:
36-
- OpenCover.Console.exe -register:user -target:"%xunit20%\xunit.console.x86.exe" -targetargs:".\src\Ninject.Extensions.Factory.Test\bin\Release\net452\Ninject.Extensions.Factory.Test.dll -noshadow" -filter:"+[Ninject.Extensions.Factory]*" -output:".\Ninject.Extensions.Factory_coverage.xml"
37-
- codecov -f "Ninject.Extensions.Factory_coverage.xml
37+
- cd src\Ninject.Extensions.Factory.Test
38+
- OpenCover.Console.exe -oldstyle -register:user -target:"C:\Program Files\dotnet\dotnet.exe" -targetargs:"xunit -configuration Release -nobuild" -filter:"+[Ninject.Extensions.Factory]*" -output:".\Ninject.Extensions.Factory_coverage.xml"
39+
- codecov -f "Ninject.Extensions.Factory_coverage.xml"
3840

3941
artifacts:
4042
- path: '**\*.nupkg'

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ public class FactoryTests : IDisposable
3636
public FactoryTests()
3737
{
3838
this.kernel = new StandardKernel();
39-
#if NO_ASSEMBLY_SCANNING
40-
this.kernel.Load(new FuncModule());
41-
#endif
4239
}
4340

4441
public void Dispose()

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ public class FuncTests : IDisposable
3939
public FuncTests()
4040
{
4141
this.kernel = new StandardKernel();
42-
#if NO_ASSEMBLY_SCANNING
43-
this.kernel.Load(new FuncModule());
44-
#endif
4542
}
4643

4744
public void Dispose()

src/Ninject.Extensions.Factory.Test/Ninject.Extensions.Factory.Test.csproj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net452</TargetFramework>
4+
<TargetFrameworks>netcoreapp2.0;net452</TargetFrameworks>
55
<IsPackable>false</IsPackable>
66
</PropertyGroup>
77

@@ -10,11 +10,11 @@
1010
<PackageReference Include="FluentAssertions" Version="4.19.4" />
1111
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
1212
<PackageReference Include="Moq" Version="4.7.99" />
13-
<PackageReference Include="xunit" Version="2.2.0" />
13+
<PackageReference Include="xunit" Version="2.3.0-rc3-build3818" />
1414
</ItemGroup>
1515

1616
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
17-
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
17+
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-rc3-build3818" />
1818
</ItemGroup>
1919

2020
<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
@@ -26,4 +26,8 @@
2626
<ProjectReference Include="..\Ninject.Extensions.Factory\Ninject.Extensions.Factory.csproj" />
2727
</ItemGroup>
2828

29+
<ItemGroup>
30+
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-rc3-build3818" />
31+
</ItemGroup>
32+
2933
</Project>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// -------------------------------------------------------------------------------------------------
2+
// <copyright file="LazyConstructorScorer.cs" company="Ninject Project Contributors">
3+
// Copyright (c) 2009-2017 Ninject Project Contributors
4+
// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
5+
// </copyright>
6+
// -------------------------------------------------------------------------------------------------
7+
8+
namespace Ninject.Extensions.Factory
9+
{
10+
using System;
11+
using Ninject.Activation;
12+
using Ninject.Planning.Directives;
13+
using Ninject.Selection.Heuristics;
14+
15+
/// <summary>
16+
/// Scores constructors by either looking for the existence of an injection marker
17+
/// attribute, or by counting the number of parameters.
18+
/// </summary>
19+
public class LazyConstructorScorer : StandardConstructorScorer
20+
{
21+
/// <summary>
22+
/// Gets the score for the specified constructor.
23+
/// </summary>
24+
/// <param name="context">The injection context.</param>
25+
/// <param name="directive">The constructor.</param>
26+
/// <returns>The constructor's score.</returns>
27+
public override int Score(IContext context, ConstructorInjectionDirective directive)
28+
{
29+
if (context.Request.Service.IsGenericType &&
30+
context.Request.Service.GetGenericTypeDefinition() == typeof(Lazy<>))
31+
{
32+
if (directive.Constructor.GetParameters().Length == 1 &&
33+
directive.Constructor.GetParameters()[0].ParameterType.IsGenericType)
34+
{
35+
return 1;
36+
}
37+
else
38+
{
39+
return 0;
40+
}
41+
}
42+
else
43+
{
44+
return base.Score(context, directive);
45+
}
46+
}
47+
}
48+
}

src/Ninject.Extensions.Factory/FuncModule.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace Ninject.Extensions.Factory
1717

1818
using Ninject.Activation;
1919
using Ninject.Modules;
20+
using Ninject.Selection.Heuristics;
2021
using Ninject.Syntax;
2122

2223
/// <summary>
@@ -42,6 +43,9 @@ public override void Load()
4243
.When(request => typeof(IFactoryProxy).IsAssignableFrom(request.Target.Member.ReflectedType));
4344
#endif
4445

46+
this.Kernel.Components.Remove<IConstructorScorer, StandardConstructorScorer>();
47+
this.Kernel.Components.Add<IConstructorScorer, LazyConstructorScorer>();
48+
4549
this.Bind(typeof(Func<>)).ToProvider<FuncProvider>();
4650
this.Bind(typeof(Func<,>)).ToProvider<FuncProvider>();
4751
this.Bind(typeof(Func<,,>)).ToProvider<FuncProvider>();

src/Ninject.Extensions.Factory/Ninject.Extensions.Factory.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
<ItemGroup>
3939
<PackageReference Include="Castle.Core" Version="4.1.1" />
40-
<PackageReference Include="Ninject" Version="3.3.1" />
40+
<PackageReference Include="Ninject" Version="3.3.2-beta1" />
4141
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta004">
4242
<PrivateAssets>All</PrivateAssets>
4343
</PackageReference>

0 commit comments

Comments
 (0)