Skip to content

Commit

Permalink
chore release: Updating dependencies to .net 6
Browse files Browse the repository at this point in the history
  • Loading branch information
Schmaga committed Dec 5, 2021
1 parent 0736409 commit 35cf0ea
Show file tree
Hide file tree
Showing 6 changed files with 413 additions and 426 deletions.
Original file line number Diff line number Diff line change
@@ -1,87 +1,83 @@
namespace MediatR.Extensions.Microsoft.AspNetCore

using System.Reflection;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using MediatR.Extensions.Microsoft.AspNetCore.Mediator;

namespace MediatR.Extensions.Microsoft.AspNetCore;
/// <summary>
/// Entry point for registration extension methods that work on top of IMvcBuilder
/// </summary>
public static class AspNetCoreMediatRServiceCollectionExtensions
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using global::Microsoft.AspNetCore.Http;
using global::Microsoft.Extensions.DependencyInjection;
using Mediator;
/// <summary>
/// Registers MediatR which is configured to use the HttpContext.RequestAborted CancellationToken in ASP.NET Core Environments, and scans the provided assemblies for handlers and requests
/// </summary>
/// <param name="mvcBuilder">Mvc Builder</param>
/// <param name="assemblies">Assemblies to scan for requests and handlers</param>
/// <returns></returns>
public static IMvcBuilder AddMediatRUsingRequestAbortedCancellationToken(this IMvcBuilder mvcBuilder, params Assembly[] assemblies)
=> mvcBuilder.AddMediatRUsingRequestAbortedCancellationToken(null, assemblies);

/// <summary>
/// Entry point for registration extension methods that work on top of IMvcBuilder
/// Registers MediatR which is configured to use the HttpContext.RequestAborted CancellationToken in ASP.NET Core Environments, and scans the provided assemblies for handlers and requests
/// </summary>
public static class AspNetCoreMediatRServiceCollectionExtensions
/// <param name="mvcBuilder">Mvc Builder</param>
/// <param name="configuration">The action used to optionally configure the MediatR options</param>
/// <param name="assemblies">Assemblies to scan for requests and handlers</param>
/// <returns></returns>
public static IMvcBuilder AddMediatRUsingRequestAbortedCancellationToken(this IMvcBuilder mvcBuilder, Action<MediatRServiceConfiguration>? configuration, params Assembly[] assemblies)
{
/// <summary>
/// Registers MediatR which is configured to use the HttpContext.RequestAborted CancellationToken in ASP.NET Core Environments, and scans the provided assemblies for handlers and requests
/// </summary>
/// <param name="mvcBuilder">Mvc Builder</param>
/// <param name="assemblies">Assemblies to scan for requests and handlers</param>
/// <returns></returns>
public static IMvcBuilder AddMediatRUsingRequestAbortedCancellationToken(this IMvcBuilder mvcBuilder, params Assembly[] assemblies)
=> mvcBuilder.AddMediatRUsingRequestAbortedCancellationToken(null, assemblies);
var serviceConfig = new MediatRServiceConfiguration();
configuration?.Invoke(serviceConfig);

/// <summary>
/// Registers MediatR which is configured to use the HttpContext.RequestAborted CancellationToken in ASP.NET Core Environments, and scans the provided assemblies for handlers and requests
/// </summary>
/// <param name="mvcBuilder">Mvc Builder</param>
/// <param name="configuration">The action used to optionally configure the MediatR options</param>
/// <param name="assemblies">Assemblies to scan for requests and handlers</param>
/// <returns></returns>
public static IMvcBuilder AddMediatRUsingRequestAbortedCancellationToken(this IMvcBuilder mvcBuilder, Action<MediatRServiceConfiguration>? configuration, params Assembly[] assemblies)
{
var serviceConfig = new MediatRServiceConfiguration();
configuration?.Invoke(serviceConfig);
mvcBuilder.Services.AddMediatR(assemblies, configuration);
ConfigureMediatorDecorator(mvcBuilder.Services, serviceConfig);

mvcBuilder.Services.AddMediatR(assemblies, configuration);
ConfigureMediatorDecorator(mvcBuilder.Services, serviceConfig);

return mvcBuilder;
}
return mvcBuilder;
}

/// <summary>
/// Registers MediatR which is configured to use the HttpContext.RequestAborted CancellationToken in ASP.NET Core Environments, and scans the assemblies of the provided types for handlers and requests
/// </summary>
/// <param name="mvcBuilder">Mvc Builder</param>
/// <param name="handlerAssemblyMarkerTypes">Assembly handler marker types</param>
/// <returns></returns>
public static IMvcBuilder AddMediatRUsingRequestAbortedCancellationToken(this IMvcBuilder mvcBuilder, params Type[] handlerAssemblyMarkerTypes)
=> mvcBuilder.AddMediatRUsingRequestAbortedCancellationToken(handlerAssemblyMarkerTypes, null);
/// <summary>
/// Registers MediatR which is configured to use the HttpContext.RequestAborted CancellationToken in ASP.NET Core Environments, and scans the assemblies of the provided types for handlers and requests
/// </summary>
/// <param name="mvcBuilder">Mvc Builder</param>
/// <param name="handlerAssemblyMarkerTypes">Assembly handler marker types</param>
/// <returns></returns>
public static IMvcBuilder AddMediatRUsingRequestAbortedCancellationToken(this IMvcBuilder mvcBuilder, params Type[] handlerAssemblyMarkerTypes)
=> mvcBuilder.AddMediatRUsingRequestAbortedCancellationToken(handlerAssemblyMarkerTypes, null);

/// <summary>
/// Registers MediatR which is configured to use the HttpContext.RequestAborted CancellationToken in ASP.NET Core Environments, and scans the assemblies of the provided types for handlers and requests
/// </summary>
/// <param name="mvcBuilder">Mvc Builder</param>
/// <param name="configuration">The action used to optionally configure the MediatR options</param>
/// <param name="handlerAssemblyMarkerTypes">Assembly handler marker types</param>
/// <returns></returns>
public static IMvcBuilder AddMediatRUsingRequestAbortedCancellationToken(this IMvcBuilder mvcBuilder, Action<MediatRServiceConfiguration> configuration, params Type[] handlerAssemblyMarkerTypes)
=> mvcBuilder.AddMediatRUsingRequestAbortedCancellationToken(handlerAssemblyMarkerTypes, configuration);
/// <summary>
/// Registers MediatR which is configured to use the HttpContext.RequestAborted CancellationToken in ASP.NET Core Environments, and scans the assemblies of the provided types for handlers and requests
/// </summary>
/// <param name="mvcBuilder">Mvc Builder</param>
/// <param name="configuration">The action used to optionally configure the MediatR options</param>
/// <param name="handlerAssemblyMarkerTypes">Assembly handler marker types</param>
/// <returns></returns>
public static IMvcBuilder AddMediatRUsingRequestAbortedCancellationToken(this IMvcBuilder mvcBuilder, Action<MediatRServiceConfiguration> configuration, params Type[] handlerAssemblyMarkerTypes)
=> mvcBuilder.AddMediatRUsingRequestAbortedCancellationToken(handlerAssemblyMarkerTypes, configuration);

/// <summary>
/// Registers MediatR which is configured to use the HttpContext.RequestAborted CancellationToken in ASP.NET Core Environments, and scans the assemblies of the provided types for handlers and requests
/// </summary>
/// <param name="mvcBuilder">>Mvc Builder</param>
/// <param name="handlerAssemblyMarkerTypes">Assembly handler marker types</param>
/// <param name="configuration">The action used to optionally configure the MediatR options</param>
/// <returns></returns>
public static IMvcBuilder AddMediatRUsingRequestAbortedCancellationToken(
this IMvcBuilder mvcBuilder, IEnumerable<Type> handlerAssemblyMarkerTypes, Action<MediatRServiceConfiguration>? configuration)
=> mvcBuilder.AddMediatRUsingRequestAbortedCancellationToken(configuration, handlerAssemblyMarkerTypes.Select(t => t.GetTypeInfo().Assembly).ToArray());
/// <summary>
/// Registers MediatR which is configured to use the HttpContext.RequestAborted CancellationToken in ASP.NET Core Environments, and scans the assemblies of the provided types for handlers and requests
/// </summary>
/// <param name="mvcBuilder">>Mvc Builder</param>
/// <param name="handlerAssemblyMarkerTypes">Assembly handler marker types</param>
/// <param name="configuration">The action used to optionally configure the MediatR options</param>
/// <returns></returns>
public static IMvcBuilder AddMediatRUsingRequestAbortedCancellationToken(
this IMvcBuilder mvcBuilder, IEnumerable<Type> handlerAssemblyMarkerTypes, Action<MediatRServiceConfiguration>? configuration)
=> mvcBuilder.AddMediatRUsingRequestAbortedCancellationToken(configuration, handlerAssemblyMarkerTypes.Select(t => t.GetTypeInfo().Assembly).ToArray());

private static void ConfigureMediatorDecorator(IServiceCollection services, MediatRServiceConfiguration serviceConfiguration)
{
services.Add(new ServiceDescriptor(serviceConfiguration.MediatorImplementationType, serviceConfiguration.MediatorImplementationType, serviceConfiguration.Lifetime));
services.AddScoped<IMediator, RequestAbortedCancellationTokenMediatorDecorator>(
provider =>
{
var mediator = (IMediator?) provider.GetService(serviceConfiguration.MediatorImplementationType)
?? throw new InvalidOperationException($"Could not resolve Mediator implementation {serviceConfiguration.MediatorImplementationType} from service provider");
var httpContextAccessor = provider.GetService<IHttpContextAccessor>()
?? throw new InvalidOperationException("Could not resolve HttpContextAccessor from service provider.");
return new RequestAbortedCancellationTokenMediatorDecorator(mediator, httpContextAccessor);
});
}
private static void ConfigureMediatorDecorator(IServiceCollection services, MediatRServiceConfiguration serviceConfiguration)
{
services.Add(new ServiceDescriptor(serviceConfiguration.MediatorImplementationType, serviceConfiguration.MediatorImplementationType, serviceConfiguration.Lifetime));
services.AddScoped<IMediator, RequestAbortedCancellationTokenMediatorDecorator>(
provider =>
{
var mediator = (IMediator?)provider.GetService(serviceConfiguration.MediatorImplementationType)
?? throw new InvalidOperationException($"Could not resolve Mediator implementation {serviceConfiguration.MediatorImplementationType} from service provider");
var httpContextAccessor = provider.GetService<IHttpContextAccessor>()
?? throw new InvalidOperationException("Could not resolve HttpContextAccessor from service provider.");
return new RequestAbortedCancellationTokenMediatorDecorator(mediator, httpContextAccessor);
});
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>MediatR.Extensions.Microsoft.AspNetCore.snk</AssemblyOriginatorKeyFile>
Expand All @@ -16,7 +17,7 @@
<PackageLicenseExpression></PackageLicenseExpression>
<Copyright>Copyright Sebastian Kleinschmager</Copyright>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Version>3.0.1</Version>
<Version>4.0.0</Version>

<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
Expand All @@ -40,7 +41,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 35cf0ea

Please sign in to comment.