Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added support to inject constructor arguments to deeper levels using …

…new ConstructorArgument("name", value, true)
  • Loading branch information...
commit 79e00d0844d4dbf680d731c3777f7cf909740370 1 parent e2af524
@remogloor remogloor authored
View
120 Build-NinjectAndExtensionsWithReleaseTag.bat
@@ -1,25 +1,46 @@
SET NoPause=true
-SET ReleaseTag=RC2-
+SET ReleaseTag=-rc1
+mkdir ..\dist-all
+del /S /Q ..\dist-all\*
call build-release.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
+IF ERRORLEVEL 1 GOTO FAILED
+xcopy /S dist\* ..\dist-all
cd ..
+IF NOT EXIST .\ninject.extensions.contextpreservation GOTO ENDFACTORY
+ cd ninject.extensions.contextpreservation
+ del lib\Ninject\*.zip
+ copy ..\Ninject\dist\*.zip lib\Ninject
+ call UnzipDependencies.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
+ call build-release.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
+ IF ERRORLEVEL 1 GOTO FAILED
+ xcopy /S dist\* ..\dist-all
+ cd ..
+:ENDFACTORY
+
IF NOT EXIST .\ninject.extensions.contextpreservation GOTO ENDCTXPRESERVATION
cd ninject.extensions.contextpreservation
del lib\Ninject\*.zip
+ del lib\Ninject.Extensions.Factory\*.zip
copy ..\Ninject\dist\*.zip lib\Ninject
+ copy ..\Ninject.Extensions.Factory\dist\*.zip lib\Ninject.Extensions.Factory
call UnzipDependencies.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
call build-release.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
+ IF ERRORLEVEL 1 GOTO FAILED
+ xcopy /S dist\* ..\dist-all
cd ..
:ENDCTXPRESERVATION
IF NOT EXIST .\ninject.extensions.namedscope GOTO ENDNSC
cd ninject.extensions.namedscope
del lib\Ninject\*.zip
- del lib\ninject.extensions.contextpreservation\*.zip
+ del lib\Ninject.Extensions.ContextPreservation\*.zip
copy ..\Ninject\dist\*.zip lib\Ninject
copy ..\ninject.extensions.contextpreservation\dist\*.zip lib\ninject.extensions.contextpreservation
call UnzipDependencies.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
call build-release.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
+ IF ERRORLEVEL 1 GOTO FAILED
+ xcopy /S dist\* ..\dist-all
cd ..
:ENDNSC
@@ -29,41 +50,51 @@ IF NOT EXIST .\ninject.extensions.childkernel GOTO ENDCK
copy ..\Ninject\dist\*.zip lib\Ninject
call UnzipDependencies.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
call build-release.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
+ IF ERRORLEVEL 1 GOTO FAILED
+ xcopy /S dist\* ..\dist-all
cd ..
:ENDCK
IF NOT EXIST .\ninject.extensions.bbveventbroker GOTO ENDBBVEB
cd ninject.extensions.bbveventbroker
del lib\Ninject\*.zip
- del lib\ninject.extensions.contextpreservation\*.zip
- del lib\ninject.extensions.namedscope\*.zip
+ del lib\Ninject.Extensions.ContextPreservation\*.zip
+ del lib\Ninject.Extensions.NamedScope\*.zip
copy ..\Ninject\dist\*.zip lib\Ninject
copy ..\ninject.extensions.contextpreservation\dist\*.zip lib\ninject.extensions.contextpreservation
copy ..\ninject.extensions.namedscope\dist\*.zip lib\ninject.extensions.namedscope
call UnzipDependencies.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
call build-release.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
+ IF ERRORLEVEL 1 GOTO FAILED
+ xcopy /S dist\* ..\dist-all
cd ..
:ENDBBVEB
IF NOT EXIST .\ninject.extensions.dependencycreation GOTO ENDDC
cd ninject.extensions.dependencycreation
del lib\Ninject\*.zip
- del lib\ninject.extensions.contextpreservation\*.zip
- del lib\ninject.extensions.namedscope\*.zip
+ del lib\Ninject.Extensions.ContextPreservation\*.zip
+ del lib\Ninject.Extensions.NamedScope\*.zip
copy ..\Ninject\dist\*.zip lib\Ninject
copy ..\ninject.extensions.contextpreservation\dist\*.zip lib\ninject.extensions.contextpreservation
copy ..\ninject.extensions.namedscope\dist\*.zip lib\ninject.extensions.namedscope
call UnzipDependencies.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
call build-release.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
+ IF ERRORLEVEL 1 GOTO FAILED
+ xcopy /S dist\* ..\dist-all
cd ..
:ENDDC
IF NOT EXIST .\ninject.extensions.conventions GOTO ENDCONV
cd ninject.extensions.conventions
del lib\Ninject\*.zip
+ del lib\Ninject.Extensions.Factory\*.zip
copy ..\Ninject\dist\*.zip lib\Ninject
+ copy ..\Ninject.Extensions.Factory\dist\*.zip lib\Ninject.Extensions.Factory
call UnzipDependencies.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
call build-release.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
+ IF ERRORLEVEL 1 GOTO FAILED
+ xcopy /S dist\* ..\dist-all
cd ..
:ENDCONV
@@ -73,6 +104,8 @@ IF NOT EXIST ninject.extensions.interception GOTO ENDIC
copy ..\Ninject\dist\*.zip lib\Ninject
call UnzipDependencies.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
call build-release.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
+ IF ERRORLEVEL 1 GOTO FAILED
+ xcopy /S dist\* ..\dist-all
cd ..
:ENDIC
@@ -82,6 +115,8 @@ IF NOT EXIST .\ninject.extensions.logging GOTO ENDLOG
copy ..\Ninject\dist\*.zip lib\Ninject
call UnzipDependencies.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
call build-release.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
+ IF ERRORLEVEL 1 GOTO FAILED
+ xcopy /S dist\* ..\dist-all
cd ..
:ENDLOG
@@ -91,24 +126,19 @@ IF NOT EXIST .\ninject.extensions.messagebroker GOTO ENDMB
copy ..\Ninject\dist\*.zip lib\Ninject
call UnzipDependencies.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
call build-release.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
+ IF ERRORLEVEL 1 GOTO FAILED
+ xcopy /S dist\* ..\dist-all
cd ..
:ENDMB
-IF NOT EXIST .\ninject.extensions.wcf GOTO ENDWCF
- cd ninject.extensions.wcf
- del lib\Ninject\*.zip
- copy ..\Ninject\dist\*.zip lib\Ninject
- call UnzipDependencies.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
- call build-release.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
- cd ..
-:ENDWCF
-
-IF NOT EXIST .\ninject.extensions.wcf GOTO ENDWF
+IF NOT EXIST .\ninject.extensions.wf GOTO ENDWF
cd ninject.extensions.wf
del lib\Ninject\*.zip
copy ..\Ninject\dist\*.zip lib\Ninject
call UnzipDependencies.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
call build-release.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
+ IF ERRORLEVEL 1 GOTO FAILED
+ xcopy /S dist\* ..\dist-all
cd ..
:ENDWF
@@ -116,8 +146,10 @@ IF NOT EXIST .\ninject.extensions.weakeventmessagebroker GOTO ENDWEAKEB
cd ninject.extensions.weakeventmessagebroker
del lib\Ninject\*.zip
copy ..\Ninject\dist\*.zip lib\Ninject
- call UnzipDependencies.cmd
+ call UnzipDependencies.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
call build-release.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
+ IF ERRORLEVEL 1 GOTO FAILED
+ xcopy /S dist\* ..\dist-all
cd ..
:ENDWEAKEB
@@ -127,6 +159,8 @@ IF NOT EXIST .\ninject.extensions.xml GOTO ENDXML
copy ..\Ninject\dist\*.zip lib\Ninject
call UnzipDependencies.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
call build-release.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
+ IF ERRORLEVEL 1 GOTO FAILED
+ xcopy /S dist\* ..\dist-all
cd ..
:ENDXML
@@ -134,17 +168,47 @@ IF NOT EXIST .\ninject.mockingkernel GOTO ENDMK
cd ninject.mockingkernel
del lib\Ninject\*.zip
copy ..\Ninject\dist\*.zip lib\Ninject
- call UnzipDependencies.cmd
+ call UnzipDependencies.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
call build-release.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
+ IF ERRORLEVEL 1 GOTO FAILED
+ xcopy /S dist\* ..\dist-all
cd ..
:ENDMK
+IF NOT EXIST .\ninject.web.common GOTO ENDWEBCOMMON
+ cd ninject.web.common
+ del lib\Ninject\*.zip
+ copy ..\Ninject\dist\*.zip lib\Ninject
+ call UnzipDependencies.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
+ call build-release.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
+ IF ERRORLEVEL 1 GOTO FAILED
+ xcopy /S dist\* ..\dist-all
+ cd ..
+:ENDWEBCOMMON
+
+IF NOT EXIST .\ninject.extensions.wcf GOTO ENDWCF
+ cd ninject.extensions.wcf
+ del lib\Ninject\*.zip
+ del lib\Ninject.Web.Common\*.zip
+ copy ..\Ninject\dist\*.zip lib\Ninject
+ copy ..\ninject.web.common\dist\*.zip lib\ninject.web.common
+ call UnzipDependencies.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
+ call build-release.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
+ IF ERRORLEVEL 1 GOTO FAILED
+ xcopy /S dist\* ..\dist-all
+ cd ..
+:ENDWCF
+
IF NOT EXIST .\ninject.web GOTO ENDWEB
cd ninject.web
del lib\Ninject\*.zip
+ del lib\Ninject.Web.Common\*.zip
copy ..\Ninject\dist\*.zip lib\Ninject
+ copy ..\ninject.web.common\dist\*.zip lib\ninject.web.common
call UnzipDependencies.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
call build-release.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
+ IF ERRORLEVEL 1 GOTO FAILED
+ xcopy /S dist\* ..\dist-all
cd ..
:ENDWEB
@@ -152,16 +216,24 @@ IF NOT EXIST .\ninject.web GOTO ENDWEB
IF NOT EXIST .\ninject.web.mvc GOTO ENDMVC
cd ninject.web.mvc
del lib\Ninject\*.zip
+ del lib\Ninject.Web.Common\*.zip
copy ..\Ninject\dist\*.zip lib\Ninject
+ copy ..\ninject.web.common\dist\*.zip lib\ninject.web.common
cd mvc1
call UnzipDependencies.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
call build-release.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
+ IF ERRORLEVEL 1 GOTO FAILED
+ xcopy /S dist\* ..\..\dist-all
cd ..
cd mvc2
call build-release.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
+ IF ERRORLEVEL 1 GOTO FAILED
+ xcopy /S dist\* ..\..\dist-all
cd ..
cd mvc3
call build-release.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
+ IF ERRORLEVEL 1 GOTO FAILED
+ xcopy /S dist\* ..\..\dist-all
cd ..
cd ..
:ENDMVC
@@ -172,7 +244,17 @@ IF NOT EXIST .\ninject.web.mvc.fluentvalidation GOTO ENDMVCFV
copy ..\Ninject\dist\*.zip lib\Ninject
call UnzipDependencies.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
call build-release.cmd "-D:product.additionalVersionTag=%ReleaseTag%"
+ IF ERRORLEVEL 1 GOTO FAILED
+ xcopy /S dist\* ..\dist-all
cd ..
:ENDMVCFV
-pause
+
+pause
+goto END
+
+:FAILED
+cd ..
+pause
+
+:END
View
1  ReleaseNotes.txt
@@ -10,6 +10,7 @@ Version 3.0.0.0
- Added: Generic Overloads for OnActivation and OnDeactivation that can be used to cast the implementation type.
- Added: Bind<T1,T2, ...>() to define multiple interfaces for one service.
- Added: Rebind<T1,T2, ...>() to define multiple interfaces for one service.
+- Added: Support to inject constructor arguments to deeper levels using new ConstructorArgument("name", value, true)
- Changed: WhenInjectedInto matches also if the target derives from the specified type.
- Changed: ToConstant bindings are in singleton scope by default
View
80 src/Ninject.Test/Integration/ConstructorArgumentTests.cs
@@ -0,0 +1,80 @@
+//-------------------------------------------------------------------------------
+// <copyright file="ConstructorArgumentTests.cs" company="Ninject Project Contributors">
+// Copyright (c) 2009-2011 Ninject Project Contributors
+// Authors: Remo Gloor (remo.gloor@gmail.com)
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// you may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+// </copyright>
+//-------------------------------------------------------------------------------
+
+namespace Ninject.Tests.Integration
+{
+ using System;
+
+ using FluentAssertions;
+
+ using Ninject.Parameters;
+ using Ninject.Tests.Fakes;
+
+ using Xunit;
+
+ public class ConstructorArgumentTests : IDisposable
+ {
+ private StandardKernel kernel;
+
+ public ConstructorArgumentTests()
+ {
+ this.kernel = new StandardKernel();
+ }
+
+ public void Dispose()
+ {
+ this.kernel.Dispose();
+ }
+
+ [Fact]
+ public void ConstructorArgumentsArePassedToFirstLevel()
+ {
+ this.kernel.Bind<IWarrior>().To<Samurai>();
+ this.kernel.Bind<IWeapon>().To<Dagger>();
+
+ var baracks = this.kernel.Get<Barracks>(new ConstructorArgument("weapon", new Sword()));
+
+ baracks.Weapon.Should().BeOfType<Sword>();
+ baracks.Warrior.Weapon.Should().BeOfType<Dagger>();
+ }
+
+ [Fact]
+ public void ConstructorArgumentsAreNotInheritedIfNotSpecified()
+ {
+ this.kernel.Bind<IWarrior>().To<Samurai>();
+
+ Action getAction = () => this.kernel.Get<Barracks>(new ConstructorArgument("weapon", new Sword()));
+
+ getAction.ShouldThrow<ActivationException>();
+ }
+
+ [Fact]
+ public void ConstructorArgumentsAreInheritedIfSpecified()
+ {
+ this.kernel.Bind<IWarrior>().To<Samurai>();
+
+ var baracks = this.kernel.Get<Barracks>(new ConstructorArgument("weapon", new Sword(), true));
+
+ baracks.Weapon.Should().BeOfType<Sword>();
+ baracks.Warrior.Weapon.Should().BeOfType<Sword>();
+ }
+ }
+}
View
1  src/Ninject.Test/Ninject.Tests.csproj
@@ -93,6 +93,7 @@
<Compile Include="Fakes\Shield.cs" />
<Compile Include="Integration\ConstantTests.cs" />
<Compile Include="Fakes\ResolveCountingProvider.cs" />
+ <Compile Include="Integration\ConstructorArgumentTests.cs" />
<Compile Include="Integration\InterfaceSegregationWithTwoServicesTests.cs" />
<Compile Include="Integration\InterfaceSegregationWithFourServicesTests.cs" />
<Compile Include="Integration\InterfaceSegregationWithThreeServicesTests.cs" />
View
86 src/Ninject/Parameters/ConstructorArgument.cs
@@ -1,19 +1,31 @@
-#region License
-//
-// Author: Nate Kohari <nate@enkari.com>
-// Copyright (c) 2007-2010, Enkari, Ltd.
-//
-// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
-// See the file LICENSE.txt for details.
-//
-#endregion
-#region Using Directives
-using System;
-using Ninject.Activation;
-#endregion
+//-------------------------------------------------------------------------------
+// <copyright file="ConstructorArgument.cs" company="Ninject Project Contributors">
+// Copyright (c) 2007-2009, Enkari, Ltd.
+// Copyright (c) 2009-2011 Ninject Project Contributors
+// Authors: Nate Kohari (nate@enkari.com)
+// Remo Gloor (remo.gloor@gmail.com)
+//
+// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
+// you may not use this file except in compliance with one of the Licenses.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+// or
+// http://www.microsoft.com/opensource/licenses.mspx
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+// </copyright>
+//-------------------------------------------------------------------------------
namespace Ninject.Parameters
{
+ using System;
+
+ using Ninject.Activation;
using Ninject.Planning.Targets;
/// <summary>
@@ -26,21 +38,63 @@ public class ConstructorArgument : Parameter, IConstructorArgument
/// </summary>
/// <param name="name">The name of the argument to override.</param>
/// <param name="value">The value to inject into the property.</param>
- public ConstructorArgument(string name, object value) : base(name, value, false) { }
+ public ConstructorArgument(string name, object value)
+ : base(name, value, false)
+ {
+ }
/// <summary>
/// Initializes a new instance of the <see cref="ConstructorArgument"/> class.
/// </summary>
/// <param name="name">The name of the argument to override.</param>
/// <param name="valueCallback">The callback to invoke to get the value that should be injected.</param>
- public ConstructorArgument(string name, Func<IContext, object> valueCallback) : base(name, valueCallback, false) { }
+ public ConstructorArgument(string name, Func<IContext, object> valueCallback)
+ : base(name, valueCallback, false)
+ {
+ }
/// <summary>
/// Initializes a new instance of the <see cref="ConstructorArgument"/> class.
/// </summary>
/// <param name="name">The name of the argument to override.</param>
/// <param name="valueCallback">The callback to invoke to get the value that should be injected.</param>
- public ConstructorArgument(string name, Func<IContext, ITarget, object> valueCallback) : base(name, valueCallback, false) { }
+ public ConstructorArgument(string name, Func<IContext, ITarget, object> valueCallback)
+ : base(name, valueCallback, false)
+ {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ConstructorArgument"/> class.
+ /// </summary>
+ /// <param name="name">The name of the argument to override.</param>
+ /// <param name="value">The value to inject into the property.</param>
+ /// <param name="shouldInherit">Whether the parameter should be inherited into child requests.</param>
+ public ConstructorArgument(string name, object value, bool shouldInherit)
+ : base(name, value, shouldInherit)
+ {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ConstructorArgument"/> class.
+ /// </summary>
+ /// <param name="name">The name of the argument to override.</param>
+ /// <param name="valueCallback">The callback to invoke to get the value that should be injected.</param>
+ /// <param name="shouldInherit">if set to <c>true</c> [should inherit].</param>
+ public ConstructorArgument(string name, Func<IContext, object> valueCallback, bool shouldInherit)
+ : base(name, valueCallback, shouldInherit)
+ {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ConstructorArgument"/> class.
+ /// </summary>
+ /// <param name="name">The name of the argument to override.</param>
+ /// <param name="valueCallback">The callback to invoke to get the value that should be injected.</param>
+ /// <param name="shouldInherit">if set to <c>true</c> [should inherit].</param>
+ public ConstructorArgument(string name, Func<IContext, ITarget, object> valueCallback, bool shouldInherit)
+ : base(name, valueCallback, shouldInherit)
+ {
+ }
/// <summary>
/// Determines if the parameter applies to the given target.
Please sign in to comment.
Something went wrong with that request. Please try again.