-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use IServiceCollection instead of IMvcBuilder
- Loading branch information
Showing
4 changed files
with
73 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 0 additions & 65 deletions
65
src/PipelineNet.ServiceProvider.AspNetCore/MvcBuilderExtensions.cs
This file was deleted.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
src/PipelineNet.ServiceProvider.AspNetCore/ServiceCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
using PipelineNet.MiddlewareResolver; | ||
using PipelineNet.ServiceProvider.AspNetCore.MiddlewareResolver; | ||
using PipelineNet.ServiceProvider.ChainsOfResponsibility.Factories; | ||
using PipelineNet.ServiceProvider.Pipelines.Factories; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
|
||
namespace PipelineNet.ServiceProvider.AspNetCore | ||
{ | ||
/// <summary> | ||
/// Extension methods to the service collection. | ||
/// </summary> | ||
public static class ServiceCollectionExtensions | ||
{ | ||
/// <summary> | ||
/// Adds pipeline and chain of responsibility factories. Adds all middleware from assemblies. | ||
/// </summary> | ||
/// <param name="services">The service collection.</param> | ||
/// <param name="assemblies">Assemblies to scan.</param> | ||
/// <param name="lifetime">The lifetime of the registered middleware.</param> | ||
/// <returns>The service collection.</returns> | ||
/// <remarks>Middleware instances will be resolved using the <see cref="IHttpContextAccessor"/>.</remarks> | ||
public static IServiceCollection AddPipelineNetAspNetCore( | ||
this IServiceCollection services, | ||
IEnumerable<Assembly> assemblies, | ||
ServiceLifetime lifetime = ServiceLifetime.Scoped) | ||
{ | ||
if (services == null) throw new ArgumentNullException("services"); | ||
if (assemblies == null) throw new ArgumentNullException("assemblies"); | ||
|
||
services.AddMiddlewareFromAssemblies(assemblies, lifetime); | ||
|
||
services.AddHttpContextAccessor(); | ||
|
||
services.TryAddSingleton<IMiddlewareResolver, HttpContextAccessorMiddlewareResolver>(); | ||
|
||
services.TryAddSingleton(typeof(IPipelineFactory<>), typeof(AsyncPipelineFactory<>)); | ||
services.TryAddSingleton(typeof(IAsyncPipelineFactory<>), typeof(AsyncPipelineFactory<>)); | ||
services.TryAddSingleton(typeof(IResponsibilityChainFactory<,>), typeof(ResponsibilityChainFactory<,>)); | ||
services.TryAddSingleton(typeof(IAsyncResponsibilityChainFactory<,>), typeof(AsyncResponsibilityChainFactory<,>)); | ||
|
||
return services; | ||
} | ||
|
||
/// <summary> | ||
/// Adds pipeline and chain of responsibility factories. Adds all middleware from the assembly. | ||
/// </summary> | ||
/// <param name="services">The service collection.</param> | ||
/// <param name="assembly">The assembly to scan.</param> | ||
/// <param name="lifetime">The lifetime of the registered middleware.</param> | ||
/// <returns>The service collection.</returns> | ||
/// <remarks>Middleware instances will be resolved using the <see cref="IHttpContextAccessor"/>.</remarks> | ||
public static IServiceCollection AddPipelineNetAspNetCore( | ||
this IServiceCollection services, | ||
Assembly assembly, | ||
ServiceLifetime lifetime = ServiceLifetime.Scoped) | ||
{ | ||
if (services == null) throw new ArgumentNullException("services"); | ||
if (assembly == null) throw new ArgumentNullException("assembly"); | ||
|
||
return services.AddPipelineNetAspNetCore(new[] { assembly }, lifetime); | ||
} | ||
} | ||
} |