Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2026.2.0" />
<PackageReference Include="MediatR" Version="14.3.0" />
<PackageReference Include="MediatR" Version="15.0.0" />
<PackageReference Include="MediatR.Contracts" Version="2.0.1" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2026.2.0" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="10.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="10.0.14" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="10.0.14" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.14" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="10.0.14" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="11.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="11.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="11.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="11.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
using FolderProcessor.Stores;
using JetBrains.Annotations;
using MediatR;
using MediatR.Pipeline;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace FolderProcessor.Extensions.Microsoft.DependencyInjection;

Expand Down Expand Up @@ -39,8 +41,17 @@ FolderProcessorHostedService HostedServiceFactory(IServiceProvider provider)
return new FolderProcessorHostedService(watcher, false);
}

services.TryAddEnumerable(ServiceDescriptor.Transient(typeof(IPipelineBehavior<,>), typeof(RequestPreProcessorBehavior<,>)));
services.TryAddEnumerable(ServiceDescriptor.Transient(typeof(IPipelineBehavior<,>), typeof(RequestPostProcessorBehavior<,>)));
services.TryAddEnumerable(ServiceDescriptor.Transient(typeof(IPipelineBehavior<,>), typeof(RequestExceptionActionProcessorBehavior<,>)));
services.TryAddEnumerable(ServiceDescriptor.Transient(typeof(IPipelineBehavior<,>), typeof(RequestExceptionProcessorBehavior<,>)));

return services
.AddMediatR(ass)
.AddMediatR(config =>
{
config.RegisterServicesFromAssemblies(ass);
config.AutoRegisterRequestProcessors = true;
})
.AddSingleton<IFileSystem, FileSystem>()
.AddSingleton<ISeenFileStore, SeenFileStore>()
.AddSingleton<IWorkingFileStore, WorkingFileStore>()
Expand Down
4 changes: 2 additions & 2 deletions src/FolderProcessor.Host/FolderProcessor.Host.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MediatR" Version="14.3.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.14" />
<PackageReference Include="MediatR" Version="15.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="11.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/FolderProcessor/FolderProcessor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MediatR" Version="14.3.0" />
<PackageReference Include="MediatR" Version="15.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.0" />
<PackageReference Include="Polly" Version="8.9.0" />
<PackageReference Include="Polly" Version="8.9.1" />
<PackageReference Include="System.Interactive.Async" Version="7.0.1" />
<PackageReference Include="System.IO.Abstractions" Version="22.3.0" />
<PackageReference Include="System.IO.Abstractions" Version="23.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageReference Include="FluentAssertions" Version="8.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="Moq" Version="4.21.0" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="22.3.0" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="23.0.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand All @@ -27,6 +27,7 @@

<ItemGroup>
<ProjectReference Include="..\..\src\FolderProcessor\FolderProcessor.csproj" />
<ProjectReference Include="..\..\src\FolderProcessor.Extensions.Microsoft.DependencyInjection\FolderProcessor.Extensions.Microsoft.DependencyInjection.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
95 changes: 95 additions & 0 deletions test/FolderProcessor.UnitTests/StartupExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using FolderProcessor.Extensions.Microsoft.DependencyInjection;
using FolderProcessor.Models.Monitoring.Notifications;
using FolderProcessor.Monitoring.Notifications;
using MediatR;
using MediatR.Pipeline;
using Microsoft.Extensions.DependencyInjection;
using Xunit;

namespace FolderProcessor.UnitTests;

public class StartupExtensionsTests
{
[Fact]
public void AddFolderProcessor_RegistersFrameworkAndApplicationHandlers()
{
var services = new ServiceCollection();

services.AddFolderProcessor(typeof(StartupExtensionsTests).Assembly);

Assert.Contains(services, service =>
service.ServiceType == typeof(INotificationHandler<FileSeenNotification>) &&
service.ImplementationType == typeof(FileSeenNotificationHandler));
Assert.Contains(services, service =>
service.ServiceType == typeof(INotificationHandler<TestNotification>) &&
service.ImplementationType == typeof(TestNotificationHandler));
Assert.Contains(services, service =>
service.ServiceType == typeof(IRequestPreProcessor<TestRequest>) &&
service.ImplementationType == typeof(TestPreProcessor));
Assert.Contains(services, service =>
service.ServiceType == typeof(IRequestPostProcessor<TestRequest, string>) &&
service.ImplementationType == typeof(TestPostProcessor));
Assert.Single(services, service =>
service.ServiceType == typeof(IPipelineBehavior<,>) &&
service.ImplementationType == typeof(RequestPreProcessorBehavior<,>));
Assert.Single(services, service =>
service.ServiceType == typeof(IPipelineBehavior<,>) &&
service.ImplementationType == typeof(RequestPostProcessorBehavior<,>));
Assert.Single(services, service =>
service.ServiceType == typeof(IPipelineBehavior<,>) &&
service.ImplementationType == typeof(RequestExceptionActionProcessorBehavior<,>));
Assert.Single(services, service =>
service.ServiceType == typeof(IPipelineBehavior<,>) &&
service.ImplementationType == typeof(RequestExceptionProcessorBehavior<,>));
Assert.Equal(
new[]
{
typeof(RequestPreProcessorBehavior<,>),
typeof(RequestPostProcessorBehavior<,>),
typeof(RequestExceptionActionProcessorBehavior<,>),
typeof(RequestExceptionProcessorBehavior<,>)
},
services.Where(service => service.ServiceType == typeof(IPipelineBehavior<,>))
.Select(service => service.ImplementationType));
}
}

public class TestNotification : INotification
{
}

public class TestNotificationHandler : INotificationHandler<TestNotification>
{
public Task Handle(TestNotification notification, CancellationToken cancellationToken) =>
Task.CompletedTask;
}

public class TestRequest : IRequest<string>
{
}

public class TestPreProcessor : IRequestPreProcessor<TestRequest>
{
public Task Process(TestRequest request, CancellationToken cancellationToken) => Task.CompletedTask;
}

public class TestPostProcessor : IRequestPostProcessor<TestRequest, string>
{
public Task Process(TestRequest request, string response, CancellationToken cancellationToken) => Task.CompletedTask;
}

public class TestExceptionHandler : IRequestExceptionHandler<TestRequest, string, InvalidOperationException>
{
public Task Handle(TestRequest request, InvalidOperationException exception,
RequestExceptionHandlerState<string> state, CancellationToken cancellationToken) => Task.CompletedTask;
}

public class TestExceptionAction : IRequestExceptionAction<TestRequest, InvalidOperationException>
{
public Task Execute(TestRequest request, InvalidOperationException exception,
CancellationToken cancellationToken) => Task.CompletedTask;
}
Loading