Skip to content

Commit

Permalink
Added more documentation and tests. Added Type as a valid target for …
Browse files Browse the repository at this point in the history
…adding conventions +semver:major
  • Loading branch information
david-driscoll committed Jun 30, 2019
1 parent 6bab4d3 commit 0e50997
Show file tree
Hide file tree
Showing 58 changed files with 2,452 additions and 237 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Company>Rocket Surgeons Guild</Company>
<Copyright>Copyright David Driscoll © 2017</Copyright>
<Authors>David Driscoll</Authors>
<LangVersion>latest</LangVersion>
<LangVersion>8.0</LangVersion>
<PackageIconUrl>https://raw.githubusercontent.com/RocketSurgeonsGuild/graphics/master/png/rsg-patch-circle-color.png</PackageIconUrl>
<!-- <VSTestCollect>XPlat Code Coverage</VSTestCollect> -->
<UseSourceLink>true</UseSourceLink>
Expand Down
2 changes: 1 addition & 1 deletion sample/Sample.DependencyOne/Sample.DependencyOne.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
<ProjectReference Include="..\..\src\Conventions.Abstractions\Rocket.Surgery.Conventions.Abstractions.csproj" />
<ProjectReference Include="..\..\src\Conventions\Rocket.Surgery.Conventions.csproj" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
<ItemGroup>
<ProjectReference Include="..\Sample.DependencyOne\Sample.DependencyOne.csproj" />
</ItemGroup>
</Project>
</Project>
2 changes: 1 addition & 1 deletion sample/Sample.DependencyTwo/Sample.DependencyTwo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
<ItemGroup>
<ProjectReference Include="..\..\src\Conventions.Abstractions\Rocket.Surgery.Conventions.Abstractions.csproj" />
</ItemGroup>
</Project>
</Project>
1 change: 1 addition & 0 deletions src/Builders.Abstractions/IBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public interface IBuilder
/// <summary>
/// A central location for sharing state between components during the convention building process.
/// </summary>
/// <value>The properties.</value>
IDictionary<object, object> Properties { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
</PropertyGroup>
</Project>
</Project>
19 changes: 15 additions & 4 deletions src/Builders/Builder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ namespace Rocket.Surgery.Builders
{
/// <summary>
/// Abstract base class for implementing a builder
/// Implements the <see cref="Rocket.Surgery.Builders.IBuilder" />
/// </summary>
/// <seealso cref="Rocket.Surgery.Builders.IBuilder" />
public abstract class Builder : IBuilder
{
/// <summary>
/// Default constructor
/// </summary>
/// <param name="properties">The properties.</param>
protected Builder(IDictionary<object, object> properties)
{
Properties = properties ?? new Dictionary<object, object>();
Expand All @@ -16,8 +22,9 @@ protected Builder(IDictionary<object, object> properties)
/// <summary>
/// A central location for sharing state between components during the convention building process.
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
/// <param name="item">The item.</param>
/// <returns>System.Object.</returns>

public virtual object this[object item]
{
get => Properties.TryGetValue(item, out object value) ? value : null;
Expand All @@ -27,14 +34,17 @@ public virtual object this[object item]
/// <summary>
/// A central location for sharing state between components during the convention building process.
/// </summary>
/// <value>The properties.</value>
public IDictionary<object, object> Properties { get; }
}

/// <summary>
/// Abstract base class for creating builders that are attached to some parent builder
/// Useful for creating sub builds that live for a short period to augment the parent.
/// Implements the <see cref="Rocket.Surgery.Builders.Builder" />
/// </summary>
/// <typeparam name="TBuilder"></typeparam>
/// <typeparam name="TBuilder">The type of the t builder.</typeparam>
/// <seealso cref="Rocket.Surgery.Builders.Builder" />
public abstract class Builder<TBuilder> : Builder
where TBuilder : class
{
Expand All @@ -50,12 +60,13 @@ protected Builder(TBuilder parent, IDictionary<object, object> properties) : bas
/// <summary>
/// Get the parent value from this builder
/// </summary>
/// <value>The parent.</value>
public TBuilder Parent { get; }

/// <summary>
/// Exit the current builder and return the parent
/// </summary>
/// <returns></returns>
/// <returns>TBuilder.</returns>
public virtual TBuilder Exit()
{
return Parent;
Expand Down
2 changes: 1 addition & 1 deletion src/Builders/Rocket.Surgery.Builders.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
<ProjectReference Include="..\Builders.Abstractions\Rocket.Surgery.Builders.Abstractions.csproj" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
</ItemGroup>
</Project>
</Project>
8 changes: 6 additions & 2 deletions src/Conventions.Abstractions/ConventionAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@ namespace Rocket.Surgery.Conventions
{
/// <summary>
/// An attribute that defines a convention for this entire assembly
/// The type attached to the convention must implement <see cref="IConvention"/> but may also implement other interfaces
/// The type attached to the convention must implement <see cref="IConvention" /> but may also implement other interfaces
/// Implements the <see cref="System.Attribute" />
/// </summary>
/// <seealso cref="System.Attribute" />
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
public sealed class ConventionAttribute : Attribute
{
/// <summary>
/// The convention type
/// </summary>
/// <value>The type.</value>
public Type Type { get; set; }

/// <summary>
/// The type to be used with the convention type
/// </summary>
/// <param name="type"></param>
/// <param name="type">The type.</param>
/// <exception cref="NotSupportedException">Type must inherit from " + nameof(IConvention)</exception>
public ConventionAttribute(Type type)
{
if (!typeof(IConvention).GetTypeInfo().IsAssignableFrom(type.GetTypeInfo()))
Expand Down
4 changes: 4 additions & 0 deletions src/Conventions.Abstractions/ConventionContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ public static class ConventionContextExtensions
/// <summary>
/// Get a value by type from the context
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="context">The context</param>
/// <returns>T.</returns>
public static T Get<T>(this IConventionContext context)
{
return (T)context[typeof(T)];
Expand All @@ -17,8 +19,10 @@ public static T Get<T>(this IConventionContext context)
/// <summary>
/// Get a value by key from the context
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="context">The context</param>
/// <param name="key">The key where the value is saved</param>
/// <returns>T.</returns>
public static T Get<T>(this IConventionContext context, string key)
{
return (T)context[key];
Expand Down
18 changes: 15 additions & 3 deletions src/Conventions.Abstractions/ConventionEnvironments.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
namespace Rocket.Surgery.Conventions
{
/// <summary>
/// Rocket Environments.
/// </summary>
public static class RocketEnvironments
{
public static readonly string Development = "Development";
public static readonly string Staging = "Staging";
public static readonly string Production = "Production";
/// <summary>
/// Development
/// </summary>
public const string Development = "Development";
/// <summary>
/// Staging
/// </summary>
public const string Staging = "Staging";
/// <summary>
/// Production
/// </summary>
public const string Production = "Production";
}
}
4 changes: 3 additions & 1 deletion src/Conventions.Abstractions/IConvention.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ public interface IConvention { }
/// A default interface that can be used to create a convention with a known context type
/// context is used to house all the data that the convention requires to do it's job
/// This can be things like a service collection, container builder, logger, etc.
/// Implements the <see cref="Rocket.Surgery.Conventions.IConvention" />
/// </summary>
/// <typeparam name="TContext">The convention type that contains all the values for this convention to work</typeparam>
/// <seealso cref="Rocket.Surgery.Conventions.IConvention" />
public interface IConvention<in TContext> : IConvention
where TContext : IConventionContext
{
/// <summary>
/// A method that is called to register a given convention at runtime.
/// </summary>
/// <param name="context"></param>
/// <param name="context">The context.</param>
void Register(TContext context);
}
}
16 changes: 16 additions & 0 deletions src/Conventions.Abstractions/IConventionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,28 @@

namespace Rocket.Surgery.Conventions
{
/// <summary>
/// Interface IConventionBuilder
/// Implements the <see cref="Rocket.Surgery.Conventions.IConventionContainer{TBuilder, TConvention, TDelegate}" />
/// </summary>
/// <typeparam name="TBuilder">The type of the t builder.</typeparam>
/// <typeparam name="TConvention">The type of the t convention.</typeparam>
/// <typeparam name="TDelegate">The type of the t delegate.</typeparam>
/// <seealso cref="Rocket.Surgery.Conventions.IConventionContainer{TBuilder, TConvention, TDelegate}" />
public interface IConventionBuilder<out TBuilder, in TConvention, in TDelegate> : IConventionContainer<TBuilder, TConvention, TDelegate>
where TBuilder : IConventionBuilder<TBuilder, TConvention, TDelegate>
where TConvention : IConvention
where TDelegate : Delegate
{
/// <summary>
/// Gets the assembly provider.
/// </summary>
/// <value>The assembly provider.</value>
IAssemblyProvider AssemblyProvider { get; }
/// <summary>
/// Gets the assembly candidate finder.
/// </summary>
/// <value>The assembly candidate finder.</value>
IAssemblyCandidateFinder AssemblyCandidateFinder { get; }
}
}
8 changes: 6 additions & 2 deletions src/Conventions.Abstractions/IConventionComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ namespace Rocket.Surgery.Conventions
{
/// <summary>
/// A composer that allows registration of delegates and interfaces that implement an interface like the delegate
/// Implements the <see cref="Rocket.Surgery.Conventions.IConvention{TContext}" />
/// </summary>
/// <typeparam name="TContext">The context type</typeparam>
/// <typeparam name="TContribution">The contribution type</typeparam>
/// <typeparam name="TDelegate">The delegate Type</typeparam>
public interface IConventionComposer<TContext, TContribution, TDelegate> : IConvention<TContext>
/// <seealso cref="Rocket.Surgery.Conventions.IConvention{TContext}" />
public interface IConventionComposer<in TContext, TContribution, TDelegate> : IConvention<TContext>
where TContribution : IConvention<TContext>
where TContext : IConventionContext
where TDelegate : Delegate
Expand All @@ -18,14 +20,16 @@ public interface IConventionComposer<TContext, TContribution, TDelegate> : IConv

/// <summary>
/// Takes a list of conventions and composes them with the given context
/// Implements the <see cref="Rocket.Surgery.Conventions.IConvention{TContext}" />
/// </summary>
/// <seealso cref="Rocket.Surgery.Conventions.IConvention{TContext}" />
public interface IConventionComposer
{
/// <summary>
/// Uses all the conventions and calls the register method for all of them.
/// </summary>
/// <param name="context">The valid context for the types</param>
/// <param name="types">The types to compose with. This type will either be a <see cref="Delegate"/> that takes <see cref="IConventionContext"/>, or a type that implements <see cref="IConvention{IConventionContext}"/></param>
/// <param name="types">The types to compose with. This type will either be a <see cref="Delegate" /> that takes <see cref="IConventionContext" />, or a type that implements <see cref="IConvention{IConventionContext}" /></param>
void Register(IConventionContext context, IEnumerable<Type> types);
}
}
48 changes: 40 additions & 8 deletions src/Conventions.Abstractions/IConventionContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,69 +4,101 @@

namespace Rocket.Surgery.Conventions
{
/// <summary>
/// Interface IConventionContainer
/// </summary>
/// <typeparam name="TBuilder">The type of the t builder.</typeparam>
/// <typeparam name="TConvention">The type of the t convention.</typeparam>
/// <typeparam name="TDelegate">The type of the t delegate.</typeparam>
public interface IConventionContainer<out TBuilder, in TConvention, in TDelegate>
where TBuilder : IConventionContainer<TBuilder, TConvention, TDelegate>
where TConvention : IConvention
where TDelegate : Delegate
{
/// <summary>
/// Gets the scanner.
/// </summary>
/// <value>The scanner.</value>
IConventionScanner Scanner { get; }

/// <summary>
/// Adds a set of conventions to the scanner
/// </summary>
/// <param name="conventions">The additional conventions.</param>
/// <returns>The scanner</returns>
/// <returns>TBuilder.</returns>

TBuilder AppendConvention(params TConvention[] conventions);

/// <summary>
/// Adds a set of conventions to the scanner
/// </summary>
/// <param name="conventions">The conventions.</param>
/// <returns>The scanner</returns>
/// <returns>TBuilder.</returns>

TBuilder AppendConvention(IEnumerable<TConvention> conventions);

/// <summary>
/// Adds a set of conventions to the scanner
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns>TBuilder.</returns>
TBuilder AppendConvention<T>() where T : TConvention, new();

/// <summary>
/// Adds a set of conventions to the scanner
/// </summary>
/// <param name="conventions">The additional conventions.</param>
/// <returns>The scanner</returns>
/// <returns>TBuilder.</returns>

TBuilder PrependConvention(params TConvention[] conventions);

/// <summary>
/// Adds a set of conventions to the scanner
/// </summary>
/// <param name="conventions">The conventions.</param>
/// <returns>The scanner</returns>
/// <returns>TBuilder.</returns>

TBuilder PrependConvention(IEnumerable<TConvention> conventions);

/// <summary>
/// Adds a set of conventions to the scanner
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns>TBuilder.</returns>
TBuilder PrependConvention<T>() where T : TConvention, new();


/// <summary>
/// Addes a set of delegates to the scanner
/// </summary>
/// <param name="delegates">The additional delegates.</param>
/// <returns>The scanner</returns>
/// <returns>TBuilder.</returns>

TBuilder PrependDelegate(params TDelegate[] delegates);

/// <summary>
/// Adds a set of delegates to the scanner
/// </summary>
/// <param name="delegates">The conventions.</param>
/// <returns>The scanner</returns>
/// <returns>TBuilder.</returns>

TBuilder PrependDelegate(IEnumerable<TDelegate> delegates);


/// <summary>
/// Addes a set of delegates to the scanner
/// </summary>
/// <param name="delegates">The additional delegates.</param>
/// <returns>The scanner</returns>
/// <returns>TBuilder.</returns>

TBuilder AppendDelegate(params TDelegate[] delegates);

/// <summary>
/// Adds a set of delegates to the scanner
/// </summary>
/// <param name="delegates">The conventions.</param>
/// <returns>The scanner</returns>
/// <returns>TBuilder.</returns>

TBuilder AppendDelegate(IEnumerable<TDelegate> delegates);
}
}
Loading

0 comments on commit 0e50997

Please sign in to comment.