From d01d8b7aca27d4cbeaea16db013d99661d98bc85 Mon Sep 17 00:00:00 2001 From: dkschlos Date: Thu, 27 Aug 2015 13:22:13 +0200 Subject: [PATCH 1/2] Added scope configuration with attributes --- .../ConventionBindingBuilderTests.cs | 57 ++- .../Fakes/ServiceWithMultipleScopes.cs | 32 ++ .../Fakes/SingletonScopedService.cs | 30 ++ .../Fakes/ThreadScopedService.cs | 30 ++ .../Fakes/TransientScopedService.cs | 30 ++ ...inject.Extensions.Conventions.Tests.csproj | 374 +++++++++--------- .../Attributes/ScopeAttribute.cs | 32 ++ .../Attributes/SingletonScopedAttribute.cs | 33 ++ .../Attributes/ThreadScopedAttribute.cs | 33 ++ .../Attributes/TransientScopedAttribute.cs | 33 ++ .../ConventionBindingBuilder.cs | 30 +- .../ConventionSyntax.Configure.cs | 12 +- .../IConventionBindingBuilder.cs | 7 +- .../Ninject.Extensions.Conventions.csproj | 324 +++++++-------- .../Syntax/IConfigureSyntax.cs | 8 +- 15 files changed, 711 insertions(+), 354 deletions(-) create mode 100644 src/Ninject.Extensions.Conventions.Test/Fakes/ServiceWithMultipleScopes.cs create mode 100644 src/Ninject.Extensions.Conventions.Test/Fakes/SingletonScopedService.cs create mode 100644 src/Ninject.Extensions.Conventions.Test/Fakes/ThreadScopedService.cs create mode 100644 src/Ninject.Extensions.Conventions.Test/Fakes/TransientScopedService.cs create mode 100644 src/Ninject.Extensions.Conventions/Attributes/ScopeAttribute.cs create mode 100644 src/Ninject.Extensions.Conventions/Attributes/SingletonScopedAttribute.cs create mode 100644 src/Ninject.Extensions.Conventions/Attributes/ThreadScopedAttribute.cs create mode 100644 src/Ninject.Extensions.Conventions/Attributes/TransientScopedAttribute.cs diff --git a/src/Ninject.Extensions.Conventions.Test/BindingBuilder/ConventionBindingBuilderTests.cs b/src/Ninject.Extensions.Conventions.Test/BindingBuilder/ConventionBindingBuilderTests.cs index fb9045f..bdfb72b 100644 --- a/src/Ninject.Extensions.Conventions.Test/BindingBuilder/ConventionBindingBuilderTests.cs +++ b/src/Ninject.Extensions.Conventions.Test/BindingBuilder/ConventionBindingBuilderTests.cs @@ -17,8 +17,10 @@ // See the License for the specific language governing permissions and // limitations under the License. // -//------------------------------------------------------------------------------- - +//------------------------------------------------------------------------------- + +using Ninject.Extensions.Conventions.Fakes; + #if !NO_MOQ namespace Ninject.Extensions.Conventions.BindingBuilder { @@ -210,6 +212,57 @@ public void Configure() { bindingMock.Verify(b => b.InSingletonScope()); } + } + + [Fact] + public void ConfigureScopesFromAttributes() + { + var types = new[] { typeof(SingletonScopedService), typeof(ThreadScopedService), typeof(TransientScopedService) }; + var generatorMock = new Mock(); + var singletonScopedBindingMocks = new[] { CreateBindingMock(), CreateBindingMock() }; + var threadScopedBindingMocks = new[] { CreateBindingMock(), CreateBindingMock() }; + var transientScopedBindingMocks = new[] { CreateBindingMock(), CreateBindingMock() }; + + this.SetupTypeFilterGetTypes(types); + generatorMock.Setup(g => g.CreateBindings(typeof(SingletonScopedService), this.bindingRoot)).Returns(singletonScopedBindingMocks.Select(b => b.Object)); + generatorMock.Setup(g => g.CreateBindings(typeof(ThreadScopedService), this.bindingRoot)).Returns(threadScopedBindingMocks.Select(b => b.Object)); + generatorMock.Setup(g => g.CreateBindings(typeof(TransientScopedService), this.bindingRoot)).Returns(transientScopedBindingMocks.Select(b => b.Object)); + + this.testee.SelectAllTypesFrom(new Assembly[0]); + this.testee.BindWith(generatorMock.Object); + this.testee.ConfigureScopesFromAttributes(); + + foreach (var bindingMock in singletonScopedBindingMocks) + { + bindingMock.Verify(b => b.InSingletonScope()); + } + + foreach (var bindingMock in threadScopedBindingMocks) + { + bindingMock.Verify(b => b.InThreadScope()); + } + + foreach (var bindingMock in transientScopedBindingMocks) + { + bindingMock.Verify(b => b.InTransientScope()); + } + } + + [Fact] + public void ConfigureScopesFromAttributesThrowsIfServiceHasMultipleScopes() + { + var types = new[] { typeof(ServiceWithMultipleScopes) }; + var generatorMock = new Mock(); + var bindingMocks = new[] { CreateBindingMock(), CreateBindingMock() }; + + this.SetupTypeFilterGetTypes(types); + generatorMock.Setup(g => g.CreateBindings(typeof(ServiceWithMultipleScopes), this.bindingRoot)).Returns(bindingMocks.Select(b => b.Object)); + + this.testee.SelectAllTypesFrom(new Assembly[0]); + this.testee.BindWith(generatorMock.Object); + + + Assert.Throws(() => this.testee.ConfigureScopesFromAttributes()); } [Fact] diff --git a/src/Ninject.Extensions.Conventions.Test/Fakes/ServiceWithMultipleScopes.cs b/src/Ninject.Extensions.Conventions.Test/Fakes/ServiceWithMultipleScopes.cs new file mode 100644 index 0000000..617734a --- /dev/null +++ b/src/Ninject.Extensions.Conventions.Test/Fakes/ServiceWithMultipleScopes.cs @@ -0,0 +1,32 @@ +//------------------------------------------------------------------------------- +// +// Copyright (c) 2009-2011 Ninject Project Contributors +// Authors: Dominik Schlosser (dominik.schlosser@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. +// +//------------------------------------------------------------------------------- + +using Ninject.Extensions.Conventions.Attributes; + +namespace Ninject.Extensions.Conventions.Fakes +{ + [TransientScoped] + [ThreadScoped] + [SingletonScoped] + public class ServiceWithMultipleScopes + { + } +} diff --git a/src/Ninject.Extensions.Conventions.Test/Fakes/SingletonScopedService.cs b/src/Ninject.Extensions.Conventions.Test/Fakes/SingletonScopedService.cs new file mode 100644 index 0000000..d484e71 --- /dev/null +++ b/src/Ninject.Extensions.Conventions.Test/Fakes/SingletonScopedService.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------- +// +// Copyright (c) 2009-2011 Ninject Project Contributors +// Authors: Dominik Schlosser (dominik.schlosser@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. +// +//------------------------------------------------------------------------------- + +using Ninject.Extensions.Conventions.Attributes; + +namespace Ninject.Extensions.Conventions.Fakes +{ + [SingletonScoped] + public class SingletonScopedService : ThreadScopedService + { + } +} diff --git a/src/Ninject.Extensions.Conventions.Test/Fakes/ThreadScopedService.cs b/src/Ninject.Extensions.Conventions.Test/Fakes/ThreadScopedService.cs new file mode 100644 index 0000000..508df03 --- /dev/null +++ b/src/Ninject.Extensions.Conventions.Test/Fakes/ThreadScopedService.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------- +// +// Copyright (c) 2009-2011 Ninject Project Contributors +// Authors: Dominik Schlosser (dominik.schlosser@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. +// +//------------------------------------------------------------------------------- + +using Ninject.Extensions.Conventions.Attributes; + +namespace Ninject.Extensions.Conventions.Fakes +{ + [ThreadScoped] + public class ThreadScopedService + { + } +} diff --git a/src/Ninject.Extensions.Conventions.Test/Fakes/TransientScopedService.cs b/src/Ninject.Extensions.Conventions.Test/Fakes/TransientScopedService.cs new file mode 100644 index 0000000..10355d9 --- /dev/null +++ b/src/Ninject.Extensions.Conventions.Test/Fakes/TransientScopedService.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------- +// +// Copyright (c) 2009-2011 Ninject Project Contributors +// Authors: Dominik Schlosser (dominik.schlosser@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. +// +//------------------------------------------------------------------------------- + +using Ninject.Extensions.Conventions.Attributes; + +namespace Ninject.Extensions.Conventions.Fakes +{ + [TransientScoped] + public class TransientScopedService + { + } +} 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..bf220ec 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,196 @@ - - - - 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/Attributes/ScopeAttribute.cs b/src/Ninject.Extensions.Conventions/Attributes/ScopeAttribute.cs new file mode 100644 index 0000000..e8e3107 --- /dev/null +++ b/src/Ninject.Extensions.Conventions/Attributes/ScopeAttribute.cs @@ -0,0 +1,32 @@ +//------------------------------------------------------------------------------- +// +// Copyright (c) 2009-2011 Ninject Project Contributors +// Authors: Dominik Schlosser (dominik.schlosser@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. +// +//------------------------------------------------------------------------------- + +using System; +using Ninject.Syntax; + +namespace Ninject.Extensions.Conventions.Attributes +{ + [AttributeUsage(AttributeTargets.Class, Inherited = true)] + public abstract class ScopeAttribute : Attribute + { + public abstract void Configure(IBindingWhenInNamedWithOrOnSyntax binding); + } +} \ No newline at end of file diff --git a/src/Ninject.Extensions.Conventions/Attributes/SingletonScopedAttribute.cs b/src/Ninject.Extensions.Conventions/Attributes/SingletonScopedAttribute.cs new file mode 100644 index 0000000..c534655 --- /dev/null +++ b/src/Ninject.Extensions.Conventions/Attributes/SingletonScopedAttribute.cs @@ -0,0 +1,33 @@ +//------------------------------------------------------------------------------- +// +// Copyright (c) 2009-2011 Ninject Project Contributors +// Authors: Dominik Schlosser (dominik.schlosser@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. +// +//------------------------------------------------------------------------------- + +using Ninject.Syntax; + +namespace Ninject.Extensions.Conventions.Attributes +{ + public class SingletonScopedAttribute : ScopeAttribute + { + public override void Configure(IBindingWhenInNamedWithOrOnSyntax binding) + { + binding.InSingletonScope(); + } + } +} \ No newline at end of file diff --git a/src/Ninject.Extensions.Conventions/Attributes/ThreadScopedAttribute.cs b/src/Ninject.Extensions.Conventions/Attributes/ThreadScopedAttribute.cs new file mode 100644 index 0000000..7caa86a --- /dev/null +++ b/src/Ninject.Extensions.Conventions/Attributes/ThreadScopedAttribute.cs @@ -0,0 +1,33 @@ +//------------------------------------------------------------------------------- +// +// Copyright (c) 2009-2011 Ninject Project Contributors +// Authors: Dominik Schlosser (dominik.schlosser@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. +// +//------------------------------------------------------------------------------- + +using Ninject.Syntax; + +namespace Ninject.Extensions.Conventions.Attributes +{ + public class ThreadScopedAttribute : ScopeAttribute + { + public override void Configure(IBindingWhenInNamedWithOrOnSyntax binding) + { + binding.InThreadScope(); + } + } +} \ No newline at end of file diff --git a/src/Ninject.Extensions.Conventions/Attributes/TransientScopedAttribute.cs b/src/Ninject.Extensions.Conventions/Attributes/TransientScopedAttribute.cs new file mode 100644 index 0000000..0da39c8 --- /dev/null +++ b/src/Ninject.Extensions.Conventions/Attributes/TransientScopedAttribute.cs @@ -0,0 +1,33 @@ +//------------------------------------------------------------------------------- +// +// Copyright (c) 2009-2011 Ninject Project Contributors +// Authors: Dominik Schlosser (dominik.schlosser@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. +// +//------------------------------------------------------------------------------- + +using Ninject.Syntax; + +namespace Ninject.Extensions.Conventions.Attributes +{ + public class TransientScopedAttribute : ScopeAttribute + { + public override void Configure(IBindingWhenInNamedWithOrOnSyntax binding) + { + binding.InTransientScope(); + } + } +} \ No newline at end of file diff --git a/src/Ninject.Extensions.Conventions/BindingBuilder/ConventionBindingBuilder.cs b/src/Ninject.Extensions.Conventions/BindingBuilder/ConventionBindingBuilder.cs index 6d314d3..beb3cec 100644 --- a/src/Ninject.Extensions.Conventions/BindingBuilder/ConventionBindingBuilder.cs +++ b/src/Ninject.Extensions.Conventions/BindingBuilder/ConventionBindingBuilder.cs @@ -17,8 +17,10 @@ // See the License for the specific language governing permissions and // limitations under the License. // -//------------------------------------------------------------------------------- - +//------------------------------------------------------------------------------- + +using Ninject.Extensions.Conventions.Attributes; + namespace Ninject.Extensions.Conventions.BindingBuilder { using System; @@ -228,8 +230,28 @@ public void ConfigureFor(ConfigurationActionWithService configuration) { configuration(syntax, type); } - } - + } + + /// + /// Evaluates scope attributes for all types. + /// + public void ConfigureScopesFromAttributes() + { + foreach (var bindingSyntaxEntry in this.bindingSyntax) + { + var scopeAttribute = + bindingSyntaxEntry.Key.GetCustomAttributes(false).OfType().SingleOrDefault(); + + if (scopeAttribute != null) + { + foreach (var syntax in bindingSyntaxEntry.Value) + { + scopeAttribute.Configure(syntax); + } + } + } + } + private void UnionTypes() { this.allTypes = this.allTypes.Union(this.currentTypes); diff --git a/src/Ninject.Extensions.Conventions/BindingBuilder/ConventionSyntax.Configure.cs b/src/Ninject.Extensions.Conventions/BindingBuilder/ConventionSyntax.Configure.cs index 76af45b..0527253 100644 --- a/src/Ninject.Extensions.Conventions/BindingBuilder/ConventionSyntax.Configure.cs +++ b/src/Ninject.Extensions.Conventions/BindingBuilder/ConventionSyntax.Configure.cs @@ -76,6 +76,16 @@ public IConfigureForSyntax Configure(ConfigurationActionWithService configuratio { this.bindingBuilder.Configure(configuration); return this; - } + } + + /// + /// Evaluates scope attributes for all types. + /// + /// The fluent syntax. + public IConfigureForSyntax ConfigureScopesFromAttributes() + { + this.bindingBuilder.ConfigureScopesFromAttributes(); + return this; + } } } \ No newline at end of file diff --git a/src/Ninject.Extensions.Conventions/BindingBuilder/IConventionBindingBuilder.cs b/src/Ninject.Extensions.Conventions/BindingBuilder/IConventionBindingBuilder.cs index c42b4d6..624a122 100644 --- a/src/Ninject.Extensions.Conventions/BindingBuilder/IConventionBindingBuilder.cs +++ b/src/Ninject.Extensions.Conventions/BindingBuilder/IConventionBindingBuilder.cs @@ -95,6 +95,11 @@ public interface IConventionBindingBuilder /// The configuration that is applies to the bindings. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Justification = "Makes the API simpler.")] - void ConfigureFor(ConfigurationActionWithService configuration); + void ConfigureFor(ConfigurationActionWithService configuration); + + /// + /// Evaluates scope attributes for all types. + /// + void ConfigureScopesFromAttributes(); } } \ 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..cbcff8b 100644 --- a/src/Ninject.Extensions.Conventions/Ninject.Extensions.Conventions.csproj +++ b/src/Ninject.Extensions.Conventions/Ninject.Extensions.Conventions.csproj @@ -1,167 +1,171 @@ - - - - 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/IConfigureSyntax.cs b/src/Ninject.Extensions.Conventions/Syntax/IConfigureSyntax.cs index fe2ab43..2f53ac1 100644 --- a/src/Ninject.Extensions.Conventions/Syntax/IConfigureSyntax.cs +++ b/src/Ninject.Extensions.Conventions/Syntax/IConfigureSyntax.cs @@ -38,6 +38,12 @@ public interface IConfigureSyntax : IConfigureForSyntax /// /// The configuration. /// The fluent syntax. - IConfigureForSyntax Configure(ConfigurationActionWithService configuration); + IConfigureForSyntax Configure(ConfigurationActionWithService configuration); + + /// + /// Evaluates scope attributes for all types. + /// + /// The fluent syntax. + IConfigureForSyntax ConfigureScopesFromAttributes(); } } \ No newline at end of file From 46b976ee5277ea373f3b3d7867472272f669d1a3 Mon Sep 17 00:00:00 2001 From: dkschlos Date: Thu, 27 Aug 2015 13:39:01 +0200 Subject: [PATCH 2/2] Added missing xml-comments --- .../Attributes/ScopeAttribute.cs | 6 ++++++ .../Attributes/SingletonScopedAttribute.cs | 6 ++++++ .../Attributes/ThreadScopedAttribute.cs | 6 ++++++ .../Attributes/TransientScopedAttribute.cs | 6 ++++++ 4 files changed, 24 insertions(+) diff --git a/src/Ninject.Extensions.Conventions/Attributes/ScopeAttribute.cs b/src/Ninject.Extensions.Conventions/Attributes/ScopeAttribute.cs index e8e3107..680d3d5 100644 --- a/src/Ninject.Extensions.Conventions/Attributes/ScopeAttribute.cs +++ b/src/Ninject.Extensions.Conventions/Attributes/ScopeAttribute.cs @@ -24,9 +24,15 @@ namespace Ninject.Extensions.Conventions.Attributes { + /// + /// Scope attributes have to inherit from this class + /// [AttributeUsage(AttributeTargets.Class, Inherited = true)] public abstract class ScopeAttribute : Attribute { + /// + /// Add scope configuration to binding + /// public abstract void Configure(IBindingWhenInNamedWithOrOnSyntax binding); } } \ No newline at end of file diff --git a/src/Ninject.Extensions.Conventions/Attributes/SingletonScopedAttribute.cs b/src/Ninject.Extensions.Conventions/Attributes/SingletonScopedAttribute.cs index c534655..b054175 100644 --- a/src/Ninject.Extensions.Conventions/Attributes/SingletonScopedAttribute.cs +++ b/src/Ninject.Extensions.Conventions/Attributes/SingletonScopedAttribute.cs @@ -23,8 +23,14 @@ namespace Ninject.Extensions.Conventions.Attributes { + /// + /// Type is a singleton + /// public class SingletonScopedAttribute : ScopeAttribute { + /// + /// Adds singleton-scope configuration to binding + /// public override void Configure(IBindingWhenInNamedWithOrOnSyntax binding) { binding.InSingletonScope(); diff --git a/src/Ninject.Extensions.Conventions/Attributes/ThreadScopedAttribute.cs b/src/Ninject.Extensions.Conventions/Attributes/ThreadScopedAttribute.cs index 7caa86a..53cd11a 100644 --- a/src/Ninject.Extensions.Conventions/Attributes/ThreadScopedAttribute.cs +++ b/src/Ninject.Extensions.Conventions/Attributes/ThreadScopedAttribute.cs @@ -23,8 +23,14 @@ namespace Ninject.Extensions.Conventions.Attributes { + /// + /// Type is thread scoped + /// public class ThreadScopedAttribute : ScopeAttribute { + /// + /// Adds thread-scope configuration to binding + /// public override void Configure(IBindingWhenInNamedWithOrOnSyntax binding) { binding.InThreadScope(); diff --git a/src/Ninject.Extensions.Conventions/Attributes/TransientScopedAttribute.cs b/src/Ninject.Extensions.Conventions/Attributes/TransientScopedAttribute.cs index 0da39c8..ddbe137 100644 --- a/src/Ninject.Extensions.Conventions/Attributes/TransientScopedAttribute.cs +++ b/src/Ninject.Extensions.Conventions/Attributes/TransientScopedAttribute.cs @@ -23,8 +23,14 @@ namespace Ninject.Extensions.Conventions.Attributes { + /// + /// Type is transient scoped + /// public class TransientScopedAttribute : ScopeAttribute { + /// + /// Adds transient-scope configuration to binding + /// public override void Configure(IBindingWhenInNamedWithOrOnSyntax binding) { binding.InTransientScope();