Skip to content

Commit

Permalink
add <GenerateDocumentationFile> and missing xml comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusz96 committed Aug 2, 2024
1 parent 00fa5e8 commit 68f4219
Show file tree
Hide file tree
Showing 20 changed files with 82 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,23 @@ namespace PipelineNet.ServiceProvider.MiddlewareResolver
{
/// <summary>
/// An implementation of <see cref="IMiddlewareResolver"/> that creates
/// instances using the <see cref="Microsoft.Extensions.DependencyInjection.ActivatorUtilities"/>.
/// instances using the <see cref="ActivatorUtilities"/>.
/// </summary>
public class ActivatorUtilitiesMiddlewareResolver : IMiddlewareResolver
{
private readonly IServiceProvider _serviceProvider;

/// <summary>
/// Creates a new <see cref="ActivatorUtilitiesMiddlewareResolver"/>.
/// </summary>
/// <param name="serviceProvider">The <see cref="IServiceProvider"/>.</param>
public ActivatorUtilitiesMiddlewareResolver(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider ?? throw new ArgumentNullException("serviceProvider",
"An instance of IServiceProvider must be provided."); ;
}

/// <inheritdoc/>
public MiddlewareResolverResult Resolve(Type type)
{
var middleware = ActivatorUtilities.CreateInstance(_serviceProvider, type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,28 @@
namespace PipelineNet.ServiceProvider.MiddlewareResolver
{
/// <summary>
/// An implementation of <see cref="IMiddlewareResolver"/> that creates
/// An implementation of <see cref="IMiddlewareResolver"/> that resolves
/// instances using the <see cref="IServiceProvider"/>.
/// </summary>
public class ServiceProviderMiddlewareResolver : IMiddlewareResolver
{
private readonly IServiceProvider _serviceProvider;

/// <summary>
/// Creates a new <see cref="ServiceProviderMiddlewareResolver"/>.
/// </summary>
/// <param name="serviceProvider">The <see cref="IServiceProvider"/>.</param>
public ServiceProviderMiddlewareResolver(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider ?? throw new ArgumentNullException("serviceProvider",
"An instance of IServiceProvider must be provided."); ;
}

/// <summary>
/// Resolves an instance of the give middleware type.
/// </summary>
/// <param name="type">The middleware type that will be resolved.</param>
/// <returns>An instance of the middleware.</returns>
public MiddlewareResolverResult Resolve(Type type)
{
var middleware = _serviceProvider.GetRequiredService(type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<Copyright>Copyright © Mariusz Stępień, Israel Valverde</Copyright>
<PackageTags>Pipeline .NetCore Portable Chain Responsibility ChainOfResponsibility Core NetStandard DI IOC DependencyInjection</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using PipelineNet.ChainsOfResponsibility;
using PipelineNet.Middleware;
using PipelineNet.MiddlewareResolver;
using System;
using System.Threading.Tasks;
using Xunit;

namespace PipelineNet.Tests.ChainsOfResponsibility
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using PipelineNet.ChainsOfResponsibility;
using PipelineNet.Middleware;
using PipelineNet.MiddlewareResolver;
using System;
using Xunit;

namespace PipelineNet.Tests.ChainsOfResponsibility
Expand Down
3 changes: 0 additions & 3 deletions src/PipelineNet.Tests/Pipelines/AsyncPipelineTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using PipelineNet.Middleware;
using PipelineNet.MiddlewareResolver;
using PipelineNet.Pipelines;
using System;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Xunit;

namespace PipelineNet.Tests.Pipelines
Expand Down
1 change: 0 additions & 1 deletion src/PipelineNet.Tests/Pipelines/PipelineTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using PipelineNet.Middleware;
using PipelineNet.MiddlewareResolver;
using PipelineNet.Pipelines;
using System;
using System.Text.RegularExpressions;
using Xunit;

Expand Down
11 changes: 11 additions & 0 deletions src/PipelineNet/BaseMiddlewareFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,20 @@

namespace PipelineNet
{
/// <summary>
/// Defines the base class for middleware flows.
/// </summary>
/// <typeparam name="TMiddleware">The middleware type.</typeparam>
public abstract class BaseMiddlewareFlow<TMiddleware>
{
/// <summary>
/// The list of middleware types.
/// </summary>
protected IList<Type> MiddlewareTypes { get; private set; }

/// <summary>
/// The resolver used to create the middleware types.
/// </summary>
protected IMiddlewareResolver MiddlewareResolver { get; private set; }

internal BaseMiddlewareFlow(IMiddlewareResolver middlewareResolver)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ public async Task<TReturn> Execute(TParameter parameter)

/// <summary>
/// Sets the function to be executed at the end of the chain as a fallback.
/// A chain can only have one finally function. Calling this method more
/// a second time will just replace the existing finally <see cref="Func{TParameter, TResult}<"/>.
/// A chain can only have one finally function. Calling this method
/// a second time will just replace the existing finally <see cref="Func{TParameter, TResult}"/>.
/// </summary>
/// <param name="finallyFunc">The function that will be execute at the end of chain.</param>
/// <returns>The current instance of <see cref="IAsyncResponsibilityChain{TParameter, TReturn}"/>.</returns>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface IAsyncResponsibilityChain<TParameter, TReturn>
{
/// <summary>
/// Sets the function to be executed at the end of the chain as a fallback.
/// A chain can only have one finally function. Calling this method more
/// A chain can only have one finally function. Calling this method
/// a second time will just replace the existing finally <see cref="Func{TParameter, TResult}"/>.
/// </summary>
/// <param name="finallyFunc">The function that will be execute at the end of chain.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface IResponsibilityChain<TParameter, TReturn>
{
/// <summary>
/// Sets the function to be executed at the end of the chain as a fallback.
/// A chain can only have one finally function. Calling this method more
/// A chain can only have one finally function. Calling this method
/// a second time will just replace the existing finally <see cref="Func{TParameter, TResult}"/>.
/// </summary>
/// <param name="finallyFunc">The <see cref="Func{TParameter, TResult}"/> that will be execute at the end of chain.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public ResponsibilityChain(IMiddlewareResolver middlewareResolver) : base(middle

/// <summary>
/// Sets the function to be executed at the end of the chain as a fallback.
/// A chain can only have one finally function. Calling this method more
/// A chain can only have one finally function. Calling this method
/// a second time will just replace the existing finally <see cref="Func{TParameter, TResult}"/>.
/// </summary>
/// <param name="finallyFunc">The <see cref="Func{TParameter, TResult}"/> that will be execute at the end of chain.</param>
Expand Down
11 changes: 11 additions & 0 deletions src/PipelineNet/Middleware/IAsyncMiddleware.WithReturn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,19 @@

namespace PipelineNet.Middleware
{
/// <summary>
/// Defines the asynchronous chain of responsibility middleware.
/// </summary>
/// <typeparam name="TParameter">The input type for the middleware.</typeparam>
/// <typeparam name="TReturn">The return type of the middleware.</typeparam>
public interface IAsyncMiddleware<TParameter, TReturn>
{
/// <summary>
/// Runs the middleware.
/// </summary>
/// <param name="parameter">The input parameter.</param>
/// <param name="next">The next middleware in the flow.</param>
/// <returns>The return value.</returns>
Task<TReturn> Run(TParameter parameter, Func<TParameter, Task<TReturn>> next);
}
}
9 changes: 9 additions & 0 deletions src/PipelineNet/Middleware/IAsyncMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@

namespace PipelineNet.Middleware
{
/// <summary>
/// Defines the asynchronous pipeline middleware.
/// </summary>
/// <typeparam name="TParameter">The type that will be the input for the middleware.</typeparam>
public interface IAsyncMiddleware<TParameter>
{
/// <summary>
/// Runs the middleware.
/// </summary>
/// <param name="parameter">The input parameter.</param>
/// <param name="next">The next middleware in the flow.</param>
Task Run(TParameter parameter, Func<TParameter, Task> next);
}
}
11 changes: 11 additions & 0 deletions src/PipelineNet/Middleware/IMiddleware.WithReturn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,19 @@

namespace PipelineNet.Middleware
{
/// <summary>
/// Defines the chain of responsibility middleware.
/// </summary>
/// <typeparam name="TParameter">The input type for the middleware.</typeparam>
/// <typeparam name="TReturn">The return type of the middleware.</typeparam>
public interface IMiddleware<TParameter, TReturn>
{
/// <summary>
/// Runs the middleware.
/// </summary>
/// <param name="parameter">The input parameter.</param>
/// <param name="next">The next middleware in the flow.</param>
/// <returns>The return value.</returns>
TReturn Run(TParameter parameter, Func<TParameter, TReturn> next);
}
}
9 changes: 9 additions & 0 deletions src/PipelineNet/Middleware/IMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@

namespace PipelineNet.Middleware
{
/// <summary>
/// Defines the pipeline middleware.
/// </summary>
/// <typeparam name="TParameter">The type that will be the input for the middleware.</typeparam>
public interface IMiddleware<TParameter>
{
/// <summary>
/// Runs the middleware.
/// </summary>
/// <param name="parameter">The input parameter.</param>
/// <param name="next">The next middleware in the flow.</param>
void Run(TParameter parameter, Action<TParameter> next);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ namespace PipelineNet.MiddlewareResolver
{
/// <summary>
/// A default implementation of <see cref="IMiddlewareResolver"/> that creates
/// instances using the <see cref="System.Activator"/>.
/// instances using the <see cref="Activator"/>.
/// </summary>
public class ActivatorMiddlewareResolver : IMiddlewareResolver
{
/// <inheritdoc/>
public MiddlewareResolverResult Resolve(Type type)
{
var middleware = Activator.CreateInstance(type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class MiddlewareResolverResult
public object Middleware { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the middleware should be disposed.
/// Gets or sets the value indicating whether the middleware should be disposed.
/// Set this to <see langword="true"/> if the middleware is IDisposable or
/// IAsyncDisposable (requires .NET Standard 2.1 or greater)
/// and was not created by a dependency injection container.
Expand Down
3 changes: 2 additions & 1 deletion src/PipelineNet/PipelineNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
<Copyright>Copyright © Israel Valverde</Copyright>
<PackageTags>Pipeline .NetCore Portable Chain Responsibility ChainOfResponsibility Core NetStandard</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<None Include="../../README.md" Pack="true" PackagePath="/" />
Expand Down
4 changes: 4 additions & 0 deletions src/PipelineNet/Pipelines/AsyncPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ namespace PipelineNet.Pipelines
/// <typeparam name="TParameter">The type that will be the input for all the middleware.</typeparam>
public class AsyncPipeline<TParameter> : BaseMiddlewareFlow<IAsyncMiddleware<TParameter>>, IAsyncPipeline<TParameter>
{
/// <summary>
/// Creates a new instance of asynchronous Pipeline.
/// </summary>
/// <param name="middlewareResolver">Resolver responsible for resolving instances out of middleware types.</param>
public AsyncPipeline(IMiddlewareResolver middlewareResolver) : base(middlewareResolver)
{ }

Expand Down

0 comments on commit 68f4219

Please sign in to comment.