From cfa496d349b2a1e6d8b63fb0d4be83191abb3699 Mon Sep 17 00:00:00 2001 From: BrunoJuchli Date: Tue, 15 Apr 2014 15:11:45 +0200 Subject: [PATCH 1/4] added IBindSyntax.Bind(); IBindSyntax.Bind(params Type[] types); --- .../ConventionSyntaxBindingTests.cs | 71 +++- .../BindingGenerators/KernelMock.cs | 53 +-- .../SpecificTypesBindingGeneratorTests.cs | 80 ++++ ...inject.Extensions.Conventions.Tests.csproj | 371 +++++++++--------- .../BindingBuilder/BindingGeneratorFactory.cs | 15 +- .../BindingBuilder/ConventionSyntax.Bind.cs | 24 +- .../IBindingGeneratorFactory.cs | 16 +- .../SpecificTypesBindingGenerator.cs | 74 ++++ .../Ninject.Extensions.Conventions.csproj | 321 +++++++-------- .../Syntax/IBindSyntax.cs | 16 +- 10 files changed, 642 insertions(+), 399 deletions(-) create mode 100644 src/Ninject.Extensions.Conventions.Test/BindingGenerators/SpecificTypesBindingGeneratorTests.cs create mode 100644 src/Ninject.Extensions.Conventions/BindingGenerators/SpecificTypesBindingGenerator.cs diff --git a/src/Ninject.Extensions.Conventions.Test/BindingBuilder/ConventionSyntaxBindingTests.cs b/src/Ninject.Extensions.Conventions.Test/BindingBuilder/ConventionSyntaxBindingTests.cs index 60db9d2..946b668 100644 --- a/src/Ninject.Extensions.Conventions.Test/BindingBuilder/ConventionSyntaxBindingTests.cs +++ b/src/Ninject.Extensions.Conventions.Test/BindingBuilder/ConventionSyntaxBindingTests.cs @@ -21,7 +21,8 @@ #if !NO_MOQ namespace Ninject.Extensions.Conventions.BindingBuilder -{ +{ + using System; using System.Text.RegularExpressions; using Moq; using Ninject.Extensions.Conventions.BindingGenerators; @@ -64,12 +65,40 @@ public void BindWith() this.testee.BindWith(generator); this.conventionBindingBuilderMock.Verify(b => b.BindWith(generator)); + } + + [Fact] + public void BindGeneric() + { + Type serviceType = typeof(string); + var generator = Mock.Of(); + this.bindingGeneratorFactoryMock + .Setup(g => g.CreateSpecificTypesBindingGenerator(serviceType)) + .Returns(generator); + + this.testee.Bind(); + + this.conventionBindingBuilderMock.Verify(b => b.BindWith(generator)); + } + + [Fact] + public void Bind() + { + Type[] serviceTypes = { typeof(string), typeof(object) }; + var generator = Mock.Of(); + this.bindingGeneratorFactoryMock + .Setup(g => g.CreateSpecificTypesBindingGenerator(serviceTypes)) + .Returns(generator); + + this.testee.Bind(serviceTypes); + + this.conventionBindingBuilderMock.Verify(b => b.BindWith(generator)); } [Fact] public void BindToAllInterfaces() - { - var generator = new Mock().Object; + { + var generator = Mock.Of(); this.bindingGeneratorFactoryMock.Setup(g => g.CreateAllInterfacesBindingGenerator()).Returns(generator); this.testee.BindAllInterfaces(); @@ -79,8 +108,8 @@ public void BindToAllInterfaces() [Fact] public void BindToAllBaseClasses() - { - var generator = new Mock().Object; + { + var generator = Mock.Of(); this.bindingGeneratorFactoryMock.Setup(g => g.CreateAllBaseClassesBindingGenerator()).Returns(generator); this.testee.BindAllBaseClasses(); @@ -90,8 +119,8 @@ public void BindToAllBaseClasses() [Fact] public void BindToBase() - { - var generator = new Mock().Object; + { + var generator = Mock.Of(); this.bindingGeneratorFactoryMock.Setup(g => g.CreateBaseBindingGenerator()).Returns(generator); this.testee.BindBase(); @@ -101,8 +130,8 @@ public void BindToBase() [Fact] public void BindToDefaultInterface() - { - var generator = new Mock().Object; + { + var generator = Mock.Of(); this.bindingGeneratorFactoryMock.Setup(g => g.CreateDefaultInterfaceBindingGenerator()).Returns(generator); this.testee.BindDefaultInterface(); @@ -112,8 +141,8 @@ public void BindToDefaultInterface() [Fact] public void BindToDefaultInterfaces() - { - var generator = new Mock().Object; + { + var generator = Mock.Of(); this.bindingGeneratorFactoryMock.Setup(g => g.CreateDefaultInterfacesBindingGenerator()).Returns(generator); this.testee.BindDefaultInterfaces(); @@ -123,8 +152,8 @@ public void BindToDefaultInterfaces() [Fact] public void BindToSelf() - { - var generator = new Mock().Object; + { + var generator = Mock.Of(); this.bindingGeneratorFactoryMock.Setup(g => g.CreateSelfBindingGenerator()).Returns(generator); this.testee.BindToSelf(); @@ -134,8 +163,8 @@ public void BindToSelf() [Fact] public void BindToSingleInterface() - { - var generator = new Mock().Object; + { + var generator = Mock.Of(); this.bindingGeneratorFactoryMock.Setup(g => g.CreateSingleInterfaceBindingGenerator()).Returns(generator); this.testee.BindSingleInterface(); @@ -146,8 +175,8 @@ public void BindToSingleInterface() [Fact] public void BindToSelection() { - ServiceSelector selector = (t1, t2) => t2; - var generator = new Mock().Object; + ServiceSelector selector = (t1, t2) => t2; + var generator = Mock.Of(); this.bindingGeneratorFactoryMock.Setup(g => g.CreateSelectorBindingGenerator(selector)).Returns(generator); this.testee.BindSelection(selector); @@ -158,8 +187,8 @@ public void BindToSelection() [Fact] public void BindToRegex() { - const string Pattern = "ThePattern"; - var generator = new Mock().Object; + const string Pattern = "ThePattern"; + var generator = Mock.Of(); this.bindingGeneratorFactoryMock.Setup(g => g.CreateRegexBindingGenerator(Pattern)).Returns(generator); this.testee.BindUsingRegex(Pattern); @@ -171,8 +200,8 @@ public void BindToRegex() public void BindToRegexWithOptions() { const string Pattern = "ThePattern"; - const RegexOptions Options = RegexOptions.Multiline; - var generator = new Mock().Object; + const RegexOptions Options = RegexOptions.Multiline; + var generator = Mock.Of(); this.bindingGeneratorFactoryMock.Setup(g => g.CreateRegexBindingGenerator(Pattern, Options)).Returns(generator); this.testee.BindUsingRegex(Pattern, Options); diff --git a/src/Ninject.Extensions.Conventions.Test/BindingGenerators/KernelMock.cs b/src/Ninject.Extensions.Conventions.Test/BindingGenerators/KernelMock.cs index 26003c8..5df8c60 100644 --- a/src/Ninject.Extensions.Conventions.Test/BindingGenerators/KernelMock.cs +++ b/src/Ninject.Extensions.Conventions.Test/BindingGenerators/KernelMock.cs @@ -57,51 +57,60 @@ public IKernel Object public List> ReturnedSyntax { get; private set; } public void VerifyBindingCreated() - { - this.VerifyBindingCreated(typeof(TInterface), typeof(TImplementation)); + { + this.VerifyBindingCreated(new[] { typeof(TInterface) }, typeof(TImplementation)); } - public void VerifyBindingCreated(Type interfaceType, Type implementationType) + public void VerifyBindingCreated(Type[] interfaceTypes, Type implementationType) { - this.Bindings.Should().Contain(new Binding(interfaceType, implementationType)); + this.Bindings.Should().Contain(new Binding(interfaceTypes, implementationType)); } public void VerifyAllBindingsCreated(IEnumerable interfaceTypes, Type implementationType) { this.Bindings.Count.Should().Be(interfaceTypes.Count()); - foreach (var interfaceType in interfaceTypes) - { - this.VerifyBindingCreated(interfaceType, implementationType); + foreach (Type interfaceType in interfaceTypes) + { + this.VerifyBindingCreated(new[] { interfaceType }, implementationType); } } private IBindingToSyntax CreateBindToMock(Type[] interfaceTypes) { - var interfaceType = interfaceTypes.Single(); var bindToMock = new Mock>(); - bindToMock.Setup(m => m.To(It.IsAny())).Returns(implementationType => this.CreateConfigSyntax(interfaceType, implementationType)); - bindToMock.Setup(m => m.ToSelf()).Returns(() => this.CreateConfigSyntax(interfaceType, interfaceType)); - return bindToMock.Object; - } + bindToMock.Setup(m => m.To(It.IsAny())).Returns(implementationType => this.CreateConfigSyntax(interfaceTypes, implementationType)); + + if (interfaceTypes.Length == 1) + { + bindToMock.Setup(m => m.ToSelf()).Returns(() => this.CreateConfigSyntax(interfaceTypes, interfaceTypes.Single())); + } + else + { + bindToMock.Setup(m => m.ToSelf()) + .Throws(new Exception(".Bind(type1, type2,..).ToSelf() is not supported. To self is only supported for .Bind(oneType).ToSelf()")); + } - private IBindingWhenInNamedWithOrOnSyntax CreateConfigSyntax(Type interfaceType, Type implementationType) + return bindToMock.Object; + } + + private IBindingWhenInNamedWithOrOnSyntax CreateConfigSyntax(Type[] interfaceTypes, Type implementationType) { var configSyntax = new Mock>().Object; this.ReturnedSyntax.Add(configSyntax); - this.Bindings.Add(new Binding(interfaceType, implementationType)); + this.Bindings.Add(new Binding(interfaceTypes, implementationType)); return configSyntax; } public class Binding { - public Binding(Type interfaceType, Type implementationType) - { - this.InterfaceType = interfaceType; + public Binding(Type[] interfaceTypes, Type implementationType) + { + this.InterfaceTypes = interfaceTypes; this.ImplementationType = implementationType; - } - - public Type InterfaceType { get; private set; } + } + + public Type[] InterfaceTypes { get; private set; } public Type ImplementationType { get; private set; } @@ -115,12 +124,12 @@ public override bool Equals(object obj) return this.ImplementationType.Equals(other.ImplementationType) && - this.InterfaceType.Equals(other.InterfaceType); + this.InterfaceTypes.SequenceEqual(other.InterfaceTypes); } public override int GetHashCode() { - return this.ImplementationType.GetHashCode() + (13 * this.InterfaceType.GetHashCode()); + return this.ImplementationType.GetHashCode() + (13 * this.InterfaceTypes.GetHashCode()); } } } diff --git a/src/Ninject.Extensions.Conventions.Test/BindingGenerators/SpecificTypesBindingGeneratorTests.cs b/src/Ninject.Extensions.Conventions.Test/BindingGenerators/SpecificTypesBindingGeneratorTests.cs new file mode 100644 index 0000000..3e9b4ed --- /dev/null +++ b/src/Ninject.Extensions.Conventions.Test/BindingGenerators/SpecificTypesBindingGeneratorTests.cs @@ -0,0 +1,80 @@ +//------------------------------------------------------------------------------- +// +// 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. +// +//------------------------------------------------------------------------------- + +#if !SILVERLIGHT_30 && !SILVERLIGHT_20 && !NO_MOQ && !NO_GENERIC_MOQ +namespace Ninject.Extensions.Conventions.BindingGenerators +{ + using System; + using System.Linq; + using FluentAssertions; + + using Ninject.Extensions.Conventions.BindingBuilder; + using Ninject.Extensions.Conventions.Fakes; + using Xunit; + + public class SpecificTypesBindingGeneratorTests + { + private static readonly Type[] ServiceTypes = { typeof(IFoo), typeof(IBar), typeof(IService) }; + + private readonly IBindingGenerator testee; + private readonly KernelMock kernelMock; + + public SpecificTypesBindingGeneratorTests() + { + this.kernelMock = new KernelMock(); + this.testee = new BindingGeneratorFactory(null).CreateSpecificTypesBindingGenerator(ServiceTypes); + } + + [Fact] + public void ExceptionIsThrownWhenTypeDoesNotImplementServiceType() + { + var type = typeof(Foo); + + var exception = Assert.Throws(() => this.testee.CreateBindings(type, this.kernelMock.Object).ToList()); + + exception.Message.Should() + .Contain(type.FullName) + .And.Contain(typeof(IBar).FullName) + .And.Contain(typeof(IService).FullName); + } + + [Fact] + public void AllServiceTypesAreBound() + { + var type = typeof(MultipleInterfaceCrazyService); + + this.testee.CreateBindings(type, this.kernelMock.Object).ToList(); + + this.kernelMock.VerifyBindingCreated(ServiceTypes, type); + } + + [Fact] + public void SyntaxForBindingIsReturned() + { + var type = typeof(MultipleInterfaceCrazyService); + + var syntax = this.testee.CreateBindings(type, this.kernelMock.Object).ToList(); + + syntax.Should().Contain(this.kernelMock.ReturnedSyntax); + } + } +} +#endif \ No newline at end of file diff --git a/src/Ninject.Extensions.Conventions.Test/Ninject.Extensions.Conventions.Tests.csproj b/src/Ninject.Extensions.Conventions.Test/Ninject.Extensions.Conventions.Tests.csproj index 81ca42e..cd69757 100644 --- a/src/Ninject.Extensions.Conventions.Test/Ninject.Extensions.Conventions.Tests.csproj +++ b/src/Ninject.Extensions.Conventions.Test/Ninject.Extensions.Conventions.Tests.csproj @@ -1,192 +1,193 @@ - - - - Debug - AnyCPU - 9.0.30729 - 2.0 - {861737AD-F1E6-4D67-9A6C-26642BA9F267} - Library - Properties - Ninject.Extensions.Conventions - Ninject.Extensions.Conventions.Tests - v4.0 - 512 - - - - - 3.5 - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - - - - - true - full - false - ..\..\build\debug\ - TRACE;DEBUG - prompt - 4 - AllRules.ruleset - false - - - pdbonly - true - ..\..\build\release\ - TRACE - prompt - 4 - AllRules.ruleset - false - - - - ..\..\lib\Ninject.Extensions.Factory\net-4.0\DynamicProxy\lib\Castle.Core.3.2.0\lib\net40-client\Castle.Core.dll - - - ..\..\tools\FluentAssertions\Net-3.5\FluentAssertions.dll - - - ..\..\tools\moq\NET40\Moq.dll - - - ..\..\lib\Ninject\net-3.5\Ninject.dll - - - ..\..\lib\Ninject.Extensions.Factory\net-4.0\Ninject.Extensions.Factory.dll - False - - - - 3.5 - - - 3.5 - - - - ..\..\tools\xunit.net\xunit.dll - - - ..\..\tools\xunit.net\xunit.extensions.dll - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - False - .NET Framework 3.5 SP1 Client Profile - false - - - False - .NET Framework 3.5 SP1 - true - - - False - Windows Installer 3.1 - true - - - - - {c9016f7b-68ce-46a7-80a7-a4592b6f0eac} - Ninject.Extensions.Conventions - - - + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {861737AD-F1E6-4D67-9A6C-26642BA9F267} + Library + Properties + Ninject.Extensions.Conventions + Ninject.Extensions.Conventions.Tests + v4.0 + 512 + + + + + 3.5 + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + + + true + full + false + ..\..\build\debug\ + TRACE;DEBUG + prompt + 4 + AllRules.ruleset + false + + + pdbonly + true + ..\..\build\release\ + TRACE + prompt + 4 + AllRules.ruleset + false + + + + ..\..\lib\Ninject.Extensions.Factory\net-4.0\DynamicProxy\lib\Castle.Core.3.2.0\lib\net40-client\Castle.Core.dll + + + ..\..\tools\FluentAssertions\Net-3.5\FluentAssertions.dll + + + ..\..\tools\moq\NET40\Moq.dll + + + ..\..\lib\Ninject\net-3.5\Ninject.dll + + + ..\..\lib\Ninject.Extensions.Factory\net-4.0\Ninject.Extensions.Factory.dll + False + + + + 3.5 + + + 3.5 + + + + ..\..\tools\xunit.net\xunit.dll + + + ..\..\tools\xunit.net\xunit.extensions.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + true + + + False + Windows Installer 3.1 + true + + + + + {c9016f7b-68ce-46a7-80a7-a4592b6f0eac} + Ninject.Extensions.Conventions + + + + --> \ No newline at end of file diff --git a/src/Ninject.Extensions.Conventions/BindingBuilder/BindingGeneratorFactory.cs b/src/Ninject.Extensions.Conventions/BindingBuilder/BindingGeneratorFactory.cs index c06ff0e..07196b9 100644 --- a/src/Ninject.Extensions.Conventions/BindingBuilder/BindingGeneratorFactory.cs +++ b/src/Ninject.Extensions.Conventions/BindingBuilder/BindingGeneratorFactory.cs @@ -23,9 +23,8 @@ namespace Ninject.Extensions.Conventions.BindingBuilder { using System; using System.Linq; - using System.Text.RegularExpressions; - - using Ninject.Components; + using System.Text.RegularExpressions; + using Ninject.Extensions.Conventions.BindingGenerators; using Ninject.Extensions.Conventions.Syntax; #if !SILVERLIGHT_20 && !WINDOWS_PHONE && !NETCF_35 @@ -49,6 +48,16 @@ public class BindingGeneratorFactory : IBindingGeneratorFactory public BindingGeneratorFactory(IBindableTypeSelector bindableTypeSelector) { this.bindableTypeSelector = bindableTypeSelector; + } + + /// + /// Creates a specific types binding generator. + /// + /// The service types the generator should create bindings for. + /// The newly created generator. + public IBindingGenerator CreateSpecificTypesBindingGenerator(params Type[] serviceTypes) + { + return new SpecificTypesBindingGenerator(serviceTypes); } /// diff --git a/src/Ninject.Extensions.Conventions/BindingBuilder/ConventionSyntax.Bind.cs b/src/Ninject.Extensions.Conventions/BindingBuilder/ConventionSyntax.Bind.cs index a1706f2..c4843a5 100644 --- a/src/Ninject.Extensions.Conventions/BindingBuilder/ConventionSyntax.Bind.cs +++ b/src/Ninject.Extensions.Conventions/BindingBuilder/ConventionSyntax.Bind.cs @@ -56,8 +56,28 @@ public IConfigureSyntax BindWith(IBindingGenerator generator) { this.bindingBuilder.BindWith(generator); return this; - } - + } + + /// + /// Binds to the type. + /// + /// The type to bind. + /// The fluent syntax + public IConfigureSyntax Bind() + { + return this.Bind(typeof(T)); + } + + /// + /// Binds to the type. + /// + /// The types to bind. + /// The fluent syntax + public IConfigureSyntax Bind(params Type[] types) + { + return this.BindWith(this.bindingGeneratorFactory.CreateSpecificTypesBindingGenerator(types)); + } + /// /// Binds all interfaces of the given types to the type. /// diff --git a/src/Ninject.Extensions.Conventions/BindingBuilder/IBindingGeneratorFactory.cs b/src/Ninject.Extensions.Conventions/BindingBuilder/IBindingGeneratorFactory.cs index 48ca855..ed7b49e 100644 --- a/src/Ninject.Extensions.Conventions/BindingBuilder/IBindingGeneratorFactory.cs +++ b/src/Ninject.Extensions.Conventions/BindingBuilder/IBindingGeneratorFactory.cs @@ -22,9 +22,8 @@ namespace Ninject.Extensions.Conventions.BindingBuilder { using System; - using System.Text.RegularExpressions; - - using Ninject.Components; + using System.Text.RegularExpressions; + using Ninject.Extensions.Conventions.BindingGenerators; using Ninject.Extensions.Conventions.Syntax; #if !SILVERLIGHT_20 && !WINDOWS_PHONE && !NETCF_35 @@ -34,8 +33,15 @@ namespace Ninject.Extensions.Conventions.BindingBuilder /// /// Factory for binding generators. /// - public interface IBindingGeneratorFactory - { + public interface IBindingGeneratorFactory + { + /// + /// Creates a specific types binding generator. + /// + /// The service types the generator should create bindings for. + /// The newly created generator. + IBindingGenerator CreateSpecificTypesBindingGenerator(params Type[] serviceTypes); + /// /// Creates a regex binding generator. /// diff --git a/src/Ninject.Extensions.Conventions/BindingGenerators/SpecificTypesBindingGenerator.cs b/src/Ninject.Extensions.Conventions/BindingGenerators/SpecificTypesBindingGenerator.cs new file mode 100644 index 0000000..da9328f --- /dev/null +++ b/src/Ninject.Extensions.Conventions/BindingGenerators/SpecificTypesBindingGenerator.cs @@ -0,0 +1,74 @@ +namespace Ninject.Extensions.Conventions.BindingGenerators +{ + using System; + using System.Collections.Generic; + using System.Globalization; + using System.Linq; + using System.Text; + using Ninject.Syntax; + + /// + /// Binds the type to all specified service types. + /// + public class SpecificTypesBindingGenerator : IBindingGenerator + { + private readonly Type[] serviceTypes; + + /// + /// Initializes a new instance of the class. + /// + /// The service types the bindings should be created for. + public SpecificTypesBindingGenerator(Type[] serviceTypes) + { + this.serviceTypes = serviceTypes; + } + + /// + /// Creates the bindings for a type. + /// + /// The type for which the bindings are created. + /// The binding root that is used to create the bindings. + /// + /// The syntaxes of the created bindings to configure more options. + /// + public IEnumerable> CreateBindings(Type type, IBindingRoot bindingRoot) + { + if (bindingRoot == null) + { + throw new ArgumentNullException("bindingRoot"); + } + + this.AssertTypeImplementsServiceTypes(type); + + return new[] + { + bindingRoot.Bind(this.serviceTypes).To(type) + }; + } + + private void AssertTypeImplementsServiceTypes(Type type) + { + var notImplementedServiceTypes = this.serviceTypes + .Where(serviceType => !serviceType.IsAssignableFrom(type)) + .ToList(); + + if (notImplementedServiceTypes.Any()) + { + var stringBuilder = new StringBuilder(); + stringBuilder + .AppendFormat(CultureInfo.InvariantCulture, "The type '{0}' does not implement the following service types: ", type.FullName) + .AppendLine(); + + foreach (Type serviceType in notImplementedServiceTypes) + { + stringBuilder + .AppendFormat(CultureInfo.InvariantCulture, " - {0}", serviceType) + .AppendLine(); + } + + stringBuilder.Append("Fix your binding to only bind service types which are implemented."); + throw new InvalidOperationException(stringBuilder.ToString()); + } + } + } +} \ No newline at end of file diff --git a/src/Ninject.Extensions.Conventions/Ninject.Extensions.Conventions.csproj b/src/Ninject.Extensions.Conventions/Ninject.Extensions.Conventions.csproj index e3d5949..7643797 100644 --- a/src/Ninject.Extensions.Conventions/Ninject.Extensions.Conventions.csproj +++ b/src/Ninject.Extensions.Conventions/Ninject.Extensions.Conventions.csproj @@ -1,167 +1,168 @@ - - - - Debug - AnyCPU - 9.0.30729 - 2.0 - {C9016F7B-68CE-46A7-80A7-A4592B6F0EAC} - Library - Properties - Ninject.Extensions.Conventions - Ninject.Extensions.Conventions - v4.0 - 512 - - - - - 3.5 - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - Client - - - true - full - false - ..\..\build\debug\ - TRACE;DEBUG - prompt - 4 - AllRules.ruleset - - - - - pdbonly - true - ..\..\build\release\ - TRACE - prompt - 4 - AllRules.ruleset - ..\..\build\release\Ninject.Extensions.Conventions.XML - true - - - true - - - ..\Ninject.snk - - - - ..\..\lib\Ninject\net-3.5\Ninject.dll - - - ..\..\lib\Ninject.Extensions.Factory\net-4.0\Ninject.Extensions.Factory.dll - False - - - - 3.5 - - - - - Properties\SharedAssemblyInfo.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - False - .NET Framework 3.5 SP1 Client Profile - false - - - False - .NET Framework 3.5 SP1 - true - - - False - Windows Installer 3.1 - true - - - - - Ninject.snk - - - + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {C9016F7B-68CE-46A7-80A7-A4592B6F0EAC} + Library + Properties + Ninject.Extensions.Conventions + Ninject.Extensions.Conventions + v4.0 + 512 + + + + + 3.5 + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + Client + + + true + full + false + ..\..\build\debug\ + TRACE;DEBUG + prompt + 4 + AllRules.ruleset + + + + + pdbonly + true + ..\..\build\release\ + TRACE + prompt + 4 + AllRules.ruleset + ..\..\build\release\Ninject.Extensions.Conventions.XML + true + + + true + + + ..\Ninject.snk + + + + ..\..\lib\Ninject\net-3.5\Ninject.dll + + + ..\..\lib\Ninject.Extensions.Factory\net-4.0\Ninject.Extensions.Factory.dll + False + + + + 3.5 + + + + + Properties\SharedAssemblyInfo.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + true + + + False + Windows Installer 3.1 + true + + + + + Ninject.snk + + + + --> \ No newline at end of file diff --git a/src/Ninject.Extensions.Conventions/Syntax/IBindSyntax.cs b/src/Ninject.Extensions.Conventions/Syntax/IBindSyntax.cs index 08e9896..08660d0 100644 --- a/src/Ninject.Extensions.Conventions/Syntax/IBindSyntax.cs +++ b/src/Ninject.Extensions.Conventions/Syntax/IBindSyntax.cs @@ -58,7 +58,21 @@ public interface IBindSyntax : IFluentSyntax /// /// The generator used to create the bindings. /// The fluent syntax - IConfigureSyntax BindWith(IBindingGenerator generator); + IConfigureSyntax BindWith(IBindingGenerator generator); + + /// + /// Binds to the type. + /// + /// The type to bind. + /// The fluent syntax + IConfigureSyntax Bind(); + + /// + /// Binds to the type. + /// + /// The types to bind. + /// The fluent syntax + IConfigureSyntax Bind(params Type[] types); /// /// Binds all interfaces of the given types to the type. From 65f57710120e4fbf99ffb365c9e71f051a9dfd28 Mon Sep 17 00:00:00 2001 From: BrunoJuchli Date: Tue, 15 Apr 2014 15:26:14 +0200 Subject: [PATCH 2/4] improved test --- .../BindingGenerators/SpecificTypesBindingGeneratorTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Ninject.Extensions.Conventions.Test/BindingGenerators/SpecificTypesBindingGeneratorTests.cs b/src/Ninject.Extensions.Conventions.Test/BindingGenerators/SpecificTypesBindingGeneratorTests.cs index 3e9b4ed..39311a0 100644 --- a/src/Ninject.Extensions.Conventions.Test/BindingGenerators/SpecificTypesBindingGeneratorTests.cs +++ b/src/Ninject.Extensions.Conventions.Test/BindingGenerators/SpecificTypesBindingGeneratorTests.cs @@ -53,7 +53,8 @@ public void ExceptionIsThrownWhenTypeDoesNotImplementServiceType() exception.Message.Should() .Contain(type.FullName) .And.Contain(typeof(IBar).FullName) - .And.Contain(typeof(IService).FullName); + .And.Contain(typeof(IService).FullName) + .And.NotContain(typeof(IFoo).FullName); } [Fact] From 85858070ae1942a29374eb85d666f359a167e5e0 Mon Sep 17 00:00:00 2001 From: BrunoJuchli Date: Tue, 15 Apr 2014 15:39:14 +0200 Subject: [PATCH 3/4] adapted mock instanciation since it seems the build server has got a problem with Mock.Of() --- .../ConventionSyntaxBindingTests.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Ninject.Extensions.Conventions.Test/BindingBuilder/ConventionSyntaxBindingTests.cs b/src/Ninject.Extensions.Conventions.Test/BindingBuilder/ConventionSyntaxBindingTests.cs index 946b668..17c7747 100644 --- a/src/Ninject.Extensions.Conventions.Test/BindingBuilder/ConventionSyntaxBindingTests.cs +++ b/src/Ninject.Extensions.Conventions.Test/BindingBuilder/ConventionSyntaxBindingTests.cs @@ -71,7 +71,7 @@ public void BindWith() public void BindGeneric() { Type serviceType = typeof(string); - var generator = Mock.Of(); + var generator = new Mock().Object; this.bindingGeneratorFactoryMock .Setup(g => g.CreateSpecificTypesBindingGenerator(serviceType)) .Returns(generator); @@ -85,7 +85,7 @@ public void BindGeneric() public void Bind() { Type[] serviceTypes = { typeof(string), typeof(object) }; - var generator = Mock.Of(); + var generator = new Mock().Object; this.bindingGeneratorFactoryMock .Setup(g => g.CreateSpecificTypesBindingGenerator(serviceTypes)) .Returns(generator); @@ -98,7 +98,7 @@ public void Bind() [Fact] public void BindToAllInterfaces() { - var generator = Mock.Of(); + var generator = new Mock().Object; this.bindingGeneratorFactoryMock.Setup(g => g.CreateAllInterfacesBindingGenerator()).Returns(generator); this.testee.BindAllInterfaces(); @@ -109,7 +109,7 @@ public void BindToAllInterfaces() [Fact] public void BindToAllBaseClasses() { - var generator = Mock.Of(); + var generator = new Mock().Object; this.bindingGeneratorFactoryMock.Setup(g => g.CreateAllBaseClassesBindingGenerator()).Returns(generator); this.testee.BindAllBaseClasses(); @@ -120,7 +120,7 @@ public void BindToAllBaseClasses() [Fact] public void BindToBase() { - var generator = Mock.Of(); + var generator = new Mock().Object; this.bindingGeneratorFactoryMock.Setup(g => g.CreateBaseBindingGenerator()).Returns(generator); this.testee.BindBase(); @@ -131,7 +131,7 @@ public void BindToBase() [Fact] public void BindToDefaultInterface() { - var generator = Mock.Of(); + var generator = new Mock().Object; this.bindingGeneratorFactoryMock.Setup(g => g.CreateDefaultInterfaceBindingGenerator()).Returns(generator); this.testee.BindDefaultInterface(); @@ -142,7 +142,7 @@ public void BindToDefaultInterface() [Fact] public void BindToDefaultInterfaces() { - var generator = Mock.Of(); + var generator = new Mock().Object; this.bindingGeneratorFactoryMock.Setup(g => g.CreateDefaultInterfacesBindingGenerator()).Returns(generator); this.testee.BindDefaultInterfaces(); @@ -153,7 +153,7 @@ public void BindToDefaultInterfaces() [Fact] public void BindToSelf() { - var generator = Mock.Of(); + var generator = new Mock().Object; this.bindingGeneratorFactoryMock.Setup(g => g.CreateSelfBindingGenerator()).Returns(generator); this.testee.BindToSelf(); @@ -164,7 +164,7 @@ public void BindToSelf() [Fact] public void BindToSingleInterface() { - var generator = Mock.Of(); + var generator = new Mock().Object; this.bindingGeneratorFactoryMock.Setup(g => g.CreateSingleInterfaceBindingGenerator()).Returns(generator); this.testee.BindSingleInterface(); @@ -176,7 +176,7 @@ public void BindToSingleInterface() public void BindToSelection() { ServiceSelector selector = (t1, t2) => t2; - var generator = Mock.Of(); + var generator = new Mock().Object; this.bindingGeneratorFactoryMock.Setup(g => g.CreateSelectorBindingGenerator(selector)).Returns(generator); this.testee.BindSelection(selector); @@ -188,7 +188,7 @@ public void BindToSelection() public void BindToRegex() { const string Pattern = "ThePattern"; - var generator = Mock.Of(); + var generator = new Mock().Object; this.bindingGeneratorFactoryMock.Setup(g => g.CreateRegexBindingGenerator(Pattern)).Returns(generator); this.testee.BindUsingRegex(Pattern); @@ -201,7 +201,7 @@ public void BindToRegexWithOptions() { const string Pattern = "ThePattern"; const RegexOptions Options = RegexOptions.Multiline; - var generator = Mock.Of(); + var generator = new Mock().Object; this.bindingGeneratorFactoryMock.Setup(g => g.CreateRegexBindingGenerator(Pattern, Options)).Returns(generator); this.testee.BindUsingRegex(Pattern, Options); From 2a49d793871b8847e205647d0ed6d77d8f183500 Mon Sep 17 00:00:00 2001 From: BrunoJuchli Date: Tue, 15 Apr 2014 15:57:22 +0200 Subject: [PATCH 4/4] updated release notes --- ReleaseNotes.txt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt index 8e2265d..e647dd8 100644 --- a/ReleaseNotes.txt +++ b/ReleaseNotes.txt @@ -1,4 +1,14 @@ -Version 3.2.0 +Version 3.2.0.1 +------------- +- Add: Support for specific service type binding IBindSyntax.Bind< + E.g. + kernel.Bind(x => x + .FromThisAssembly() + .SelectAllClasses() + .InheritedFrom() + .Bind()); + +Version 3.2.0.0 ------------- - Add: Support for multiple configurations in one BindWith E.g.