Skip to content

Commit

Permalink
Added scanner to convention builder. Added overloads to convention bu…
Browse files Browse the repository at this point in the history
…ilder similar to scanner. IConvenctionContainer can now be used as a 'root' interface for adding many conventions on a common builder (Host, WebHost, etc) +semver:major
  • Loading branch information
david-driscoll committed Jan 13, 2019
1 parent 7bd6c46 commit 7bf024d
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using Rocket.Surgery.Builders;

namespace Rocket.Surgery.Conventions.Scanners
namespace Rocket.Surgery.Conventions
{
/// <summary>
/// Class ConventionScannerExtensions.
/// </summary>
/// TODO Edit XML Comment Template for ConventionScannerExtensions
public static class ConventionScannerExtensions
public static class ConventionContainerExtensions
{
/// <summary>
/// Adds a set of conventions to the scanner
Expand All @@ -18,7 +19,7 @@ public static class ConventionScannerExtensions
/// <param name="conventions">The additional conventions.</param>
/// <returns>The scanner</returns>
public static T AppendConvention<T>(this T scanner, params IConvention[] conventions)
where T : IConventionScanner
where T : IConventionContainer
{
foreach (var type in conventions)
{
Expand All @@ -35,7 +36,7 @@ public static T AppendConvention<T>(this T scanner, params IConvention[] convent
/// <param name="types">The conventions.</param>
/// <returns>The scanner</returns>
public static T AppendConvention<T>(this T scanner, IEnumerable<IConvention> types)
where T : IConventionScanner
where T : IConventionContainer
{
foreach (var type in types)
{
Expand All @@ -52,7 +53,7 @@ public static T AppendConvention<T>(this T scanner, IEnumerable<IConvention> typ
/// <param name="conventions">The additional conventions.</param>
/// <returns>The scanner</returns>
public static T PrependConvention<T>(this T scanner, params IConvention[] conventions)
where T : IConventionScanner
where T : IConventionContainer
{
foreach (var type in conventions)
{
Expand All @@ -69,7 +70,7 @@ public static T PrependConvention<T>(this T scanner, params IConvention[] conven
/// <param name="types">The conventions.</param>
/// <returns>The scanner</returns>
public static T PrependConvention<T>(this T scanner, IEnumerable<IConvention> types)
where T : IConventionScanner
where T : IConventionContainer
{
foreach (var type in types)
{
Expand All @@ -86,7 +87,7 @@ public static T PrependConvention<T>(this T scanner, IEnumerable<IConvention> ty
/// <param name="delegates">The additional delegates.</param>
/// <returns>The scanner</returns>
public static T PrependDelegate<T>(this T scanner, params Delegate[] delegates)
where T : IConventionScanner
where T : IConventionContainer
{
foreach (var type in delegates)
{
Expand All @@ -103,7 +104,7 @@ public static T PrependDelegate<T>(this T scanner, params Delegate[] delegates)
/// <param name="delegates">The conventions.</param>
/// <returns>The scanner</returns>
public static T PrependDelegate<T>(this T scanner, IEnumerable<Delegate> delegates)
where T : IConventionScanner
where T : IConventionContainer
{
foreach (var type in delegates)
{
Expand All @@ -121,7 +122,7 @@ public static T PrependDelegate<T>(this T scanner, IEnumerable<Delegate> delegat
/// <param name="delegates">The additional delegates.</param>
/// <returns>The scanner</returns>
public static T AppendDelegate<T>(this T scanner, params Delegate[] delegates)
where T : IConventionScanner
where T : IConventionContainer
{
foreach (var type in delegates)
{
Expand All @@ -138,7 +139,7 @@ public static T AppendDelegate<T>(this T scanner, params Delegate[] delegates)
/// <param name="delegates">The conventions.</param>
/// <returns>The scanner</returns>
public static T AppendDelegate<T>(this T scanner, IEnumerable<Delegate> delegates)
where T : IConventionScanner
where T : IConventionContainer
{
foreach (var type in delegates)
{
Expand All @@ -148,69 +149,162 @@ public static T AppendDelegate<T>(this T scanner, IEnumerable<Delegate> delegate
}

/// <summary>
/// Adds an exception to the scanner to exclude a specific type
/// Adds a set of conventions to the scanner
/// </summary>
/// <typeparam name="T">The scanner</typeparam>
/// <param name="builder">The scanner.</param>
/// <param name="conventions">The additional conventions.</param>
/// <returns>The scanner</returns>
public static T AppendConvention<T, TBuilder, TConvention, TDelegate>(this T builder, params TConvention[] conventions)
where T : IConventionContainer<TBuilder, TConvention, TDelegate>
where TBuilder : IBuilder
where TConvention : IConvention
where TDelegate : Delegate
{
foreach (var type in conventions)
{
builder.AppendConvention(type);
}
return builder;
}

/// <summary>
/// Adds a set of conventions to the scanner
/// </summary>
/// <typeparam name="T">The scanner</typeparam>
/// <param name="scanner">The scanner.</param>
/// <param name="types">The additional types to exclude.</param>
/// <param name="types">The conventions.</param>
/// <returns>The scanner</returns>
public static T ExceptConvention<T>(this T scanner, params Type[] types)
where T : IConventionScanner
public static T AppendConvention<T, TBuilder, TConvention, TDelegate>(this T scanner, IEnumerable<TConvention> types)
where T : IConventionContainer<TBuilder, TConvention, TDelegate>
where TBuilder : IBuilder
where TConvention : IConvention
where TDelegate : Delegate
{
foreach (var type in types)
{
scanner.ExceptConvention(type);
scanner.AppendConvention(type);
}
return scanner;
}

/// <summary>
/// Adds a set of conventions to the scanner
/// </summary>
/// <typeparam name="T">The scanner</typeparam>
/// <param name="scanner">The scanner.</param>
/// <param name="conventions">The additional conventions.</param>
/// <returns>The scanner</returns>
public static T PrependConvention<T, TBuilder, TConvention, TDelegate>(this T scanner, params TConvention[] conventions)
where T : IConventionContainer<TBuilder, TConvention, TDelegate>
where TBuilder : IBuilder
where TConvention : IConvention
where TDelegate : Delegate
{
foreach (var type in conventions)
{
scanner.PrependConvention(type);
}
return scanner;
}

/// <summary>
/// Adds an exception to the scanner to exclude a specific type
/// Adds a set of conventions to the scanner
/// </summary>
/// <typeparam name="T">The scanner</typeparam>
/// <param name="scanner">The scanner.</param>
/// <param name="types">The convention types to exclude.</param>
/// <param name="types">The conventions.</param>
/// <returns>The scanner</returns>
public static T ExceptConvention<T>(this T scanner, IEnumerable<Type> types)
where T : IConventionScanner
public static T PrependConvention<T, TBuilder, TConvention, TDelegate>(this T scanner, IEnumerable<TConvention> types)
where T : IConventionContainer<TBuilder, TConvention, TDelegate>
where TBuilder : IBuilder
where TConvention : IConvention
where TDelegate : Delegate
{
foreach (var type in types)
{
scanner.ExceptConvention(type);
scanner.PrependConvention(type);
}
return scanner;
}

/// <summary>
/// Addes a set of delegates to the scanner
/// </summary>
/// <typeparam name="T">The scanner</typeparam>
/// <param name="scanner">The scanner.</param>
/// <param name="delegates">The additional delegates.</param>
/// <returns>The scanner</returns>
public static T PrependDelegate<T, TBuilder, TConvention, TDelegate>(this T scanner, params TDelegate[] delegates)
where T : IConventionContainer<TBuilder, TConvention, TDelegate>
where TBuilder : IBuilder
where TConvention : IConvention
where TDelegate : Delegate
{
foreach (var type in delegates)
{
scanner.PrependDelegate(type);
}
return scanner;
}

/// <summary>
/// Adds a set of delegates to the scanner
/// </summary>
/// <typeparam name="T">The scanner</typeparam>
/// <param name="scanner">The scanner.</param>
/// <param name="delegates">The conventions.</param>
/// <returns>The scanner</returns>
public static T PrependDelegate<T, TBuilder, TConvention, TDelegate>(this T scanner, IEnumerable<TDelegate> delegates)
where T : IConventionContainer<TBuilder, TConvention, TDelegate>
where TBuilder : IBuilder
where TConvention : IConvention
where TDelegate : Delegate
{
foreach (var type in delegates)
{
scanner.PrependDelegate(type);
}
return scanner;
}


/// <summary>
/// Adds an exception to the scanner to exclude a specific type
/// Addes a set of delegates to the scanner
/// </summary>
/// <typeparam name="T">The scanner</typeparam>
/// <param name="scanner">The scanner.</param>
/// <param name="assemblies">The additional types to exclude.</param>
/// <param name="delegates">The additional delegates.</param>
/// <returns>The scanner</returns>
public static T ExceptConvention<T>(this T scanner, params Assembly[] assemblies)
where T : IConventionScanner
public static T AppendDelegate<T, TBuilder, TConvention, TDelegate>(this T scanner, params TDelegate[] delegates)
where T : IConventionContainer<TBuilder, TConvention, TDelegate>
where TBuilder : IBuilder
where TConvention : IConvention
where TDelegate : Delegate
{
foreach (var type in assemblies)
foreach (var type in delegates)
{
scanner.ExceptConvention(type);
scanner.AppendDelegate(type);
}
return scanner;
}

/// <summary>
/// Adds an exception to the scanner to exclude a specific type
/// Adds a set of delegates to the scanner
/// </summary>
/// <typeparam name="T">The scanner</typeparam>
/// <param name="scanner">The scanner.</param>
/// <param name="assemblies">The convention types to exclude.</param>
/// <param name="delegates">The conventions.</param>
/// <returns>The scanner</returns>
public static T ExceptConvention<T>(this T scanner, IEnumerable<Assembly> assemblies)
where T : IConventionScanner
public static T AppendDelegate<T, TBuilder, TConvention, TDelegate>(this T scanner, IEnumerable<TDelegate> delegates)
where T : IConventionContainer<TBuilder, TConvention, TDelegate>
where TBuilder : IBuilder
where TConvention : IConvention
where TDelegate : Delegate
{
foreach (var type in assemblies)
foreach (var type in delegates)
{
scanner.ExceptConvention(type);
scanner.AppendDelegate(type);
}
return scanner;
}
Expand Down
1 change: 1 addition & 0 deletions src/Conventions.Abstractions/IConventionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public interface IConventionBuilder<out TBuilder, in TConvention, in TDelegate>
{
IAssemblyProvider AssemblyProvider { get; }
IAssemblyCandidateFinder AssemblyCandidateFinder { get; }
IConventionScanner Scanner { get; }
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using Rocket.Surgery.Builders;

namespace Rocket.Surgery.Conventions.Scanners
namespace Rocket.Surgery.Conventions
{
public interface IConventionContainer
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.Reflection;

namespace Rocket.Surgery.Conventions.Scanners
{
/// <summary>
/// Class ConventionScannerExtensions.
/// </summary>
/// TODO Edit XML Comment Template for ConventionScannerExtensions
public static class ConventionScannerExtensions
{
/// <summary>
/// Adds an exception to the scanner to exclude a specific type
/// </summary>
/// <typeparam name="T">The scanner</typeparam>
/// <param name="scanner">The scanner.</param>
/// <param name="types">The additional types to exclude.</param>
/// <returns>The scanner</returns>
public static T ExceptConvention<T>(this T scanner, params Type[] types)
where T : IConventionScanner
{
foreach (var type in types)
{
scanner.ExceptConvention(type);
}
return scanner;
}

/// <summary>
/// Adds an exception to the scanner to exclude a specific type
/// </summary>
/// <typeparam name="T">The scanner</typeparam>
/// <param name="scanner">The scanner.</param>
/// <param name="types">The convention types to exclude.</param>
/// <returns>The scanner</returns>
public static T ExceptConvention<T>(this T scanner, IEnumerable<Type> types)
where T : IConventionScanner
{
foreach (var type in types)
{
scanner.ExceptConvention(type);
}
return scanner;
}

/// <summary>
/// Adds an exception to the scanner to exclude a specific type
/// </summary>
/// <typeparam name="T">The scanner</typeparam>
/// <param name="scanner">The scanner.</param>
/// <param name="assemblies">The additional types to exclude.</param>
/// <returns>The scanner</returns>
public static T ExceptConvention<T>(this T scanner, params Assembly[] assemblies)
where T : IConventionScanner
{
foreach (var type in assemblies)
{
scanner.ExceptConvention(type);
}
return scanner;
}

/// <summary>
/// Adds an exception to the scanner to exclude a specific type
/// </summary>
/// <typeparam name="T">The scanner</typeparam>
/// <param name="scanner">The scanner.</param>
/// <param name="assemblies">The convention types to exclude.</param>
/// <returns>The scanner</returns>
public static T ExceptConvention<T>(this T scanner, IEnumerable<Assembly> assemblies)
where T : IConventionScanner
{
foreach (var type in assemblies)
{
scanner.ExceptConvention(type);
}
return scanner;
}
}
}
2 changes: 2 additions & 0 deletions src/Conventions/ConventionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ protected ConventionBuilder(IConventionScanner scanner, IAssemblyProvider assemb
{
AssemblyProvider = assemblyProvider ?? throw new ArgumentNullException(nameof(assemblyProvider));
AssemblyCandidateFinder = assemblyCandidateFinder ?? throw new ArgumentNullException(nameof(assemblyCandidateFinder));
Scanner = scanner ?? throw new ArgumentNullException(nameof(scanner));
}

public IAssemblyProvider AssemblyProvider { get; }
public IAssemblyCandidateFinder AssemblyCandidateFinder { get; }
public IConventionScanner Scanner { get; }
}
}

0 comments on commit 7bf024d

Please sign in to comment.