Skip to content

Commit

Permalink
Add csharpier for consistent formatting (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinothamar authored Apr 25, 2022
1 parent 6361866 commit 57db50d
Show file tree
Hide file tree
Showing 98 changed files with 1,084 additions and 658 deletions.
3 changes: 3 additions & 0 deletions .csharpierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"printWidth": 120
}
9 changes: 2 additions & 7 deletions Build.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
<Project Sdk="Microsoft.Build.Traversal/2.0.24">
<ItemGroup>
<ProjectReference Include="src/Mediator/Mediator.csproj" />
<ProjectReference Include="src/Mediator.SourceGenerator/Mediator.SourceGenerator.csproj" />
<ProjectReference Include="test/Mediator.SourceGenerator.Roslyn38.Tests/Mediator.SourceGenerator.Roslyn38.Tests.csproj" />
<ProjectReference Include="test/Mediator.SourceGenerator.Roslyn40.Tests/Mediator.SourceGenerator.Roslyn40.Tests.csproj" />
<ProjectReference Include="test/Mediator.Tests/Mediator.Tests.csproj" />
<ProjectReference Include="test/Mediator.Tests.TransientLifetime/Mediator.Tests.TransientLifetime.csproj" />
<ProjectReference Include="test/Mediator.Tests.ScopedLifetime/Mediator.Tests.ScopedLifetime.csproj" />
<ProjectReference Include="src/**/*.*proj" />
<ProjectReference Include="test/**/*.*proj" />
</ItemGroup>
</Project>
7 changes: 7 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,11 @@
<PropertyGroup>
<DotNetVersion>6.0.0</DotNetVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CSharpier.MsBuild" Version="0.16.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions Mediator.sln
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_files", "_files", "{FDAEEF
NuGet.config = NuGet.config
README.md = README.md
version.json = version.json
.csharpierrc.json = .csharpierrc.json
Build.csproj = Build.csproj
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mediator.Tests.TransientLifetime", "test\Mediator.Tests.TransientLifetime\Mediator.Tests.TransientLifetime.csproj", "{4C18FD08-BCE4-4C6A-9D84-9A81C4561586}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ namespace Mediator.Benchmarks.Notification;

public sealed record SomeNotification(Guid Id) : INotification, MediatR.INotification;

public sealed class SomeHandlerClass :
INotificationHandler<SomeNotification>,
MediatR.INotificationHandler<SomeNotification>,
IAsyncMessageHandler<SomeNotification>
public sealed class SomeHandlerClass
: INotificationHandler<SomeNotification>,
MediatR.INotificationHandler<SomeNotification>,
IAsyncMessageHandler<SomeNotification>
{
public ValueTask Handle(SomeNotification notification, CancellationToken cancellationToken) =>
default;
public ValueTask Handle(SomeNotification notification, CancellationToken cancellationToken) => default;

public ValueTask HandleAsync(SomeNotification message, CancellationToken cancellationToken) =>
default;
public ValueTask HandleAsync(SomeNotification message, CancellationToken cancellationToken) => default;

Task MediatR.INotificationHandler<SomeNotification>.Handle(SomeNotification notification, CancellationToken cancellationToken) =>
Task.CompletedTask;
Task MediatR.INotificationHandler<SomeNotification>.Handle(
SomeNotification notification,
CancellationToken cancellationToken
) => Task.CompletedTask;
}

[MemoryDiagnoser]
Expand Down Expand Up @@ -50,26 +50,31 @@ public void Setup()
{
var services = new ServiceCollection();
services.AddMediator(opts => opts.ServiceLifetime = ServiceLifetime);
services.AddMediatR(opts =>
{
_ = ServiceLifetime switch
services.AddMediatR(
opts =>
{
ServiceLifetime.Singleton => opts.AsSingleton(),
ServiceLifetime.Scoped => opts.AsScoped(),
ServiceLifetime.Transient => opts.AsTransient(),
_ => throw new InvalidOperationException(),
};
}, typeof(SomeHandlerClass).Assembly);
services.AddMessagePipe(opts =>
{
opts.InstanceLifetime = ServiceLifetime switch
_ = ServiceLifetime switch
{
ServiceLifetime.Singleton => opts.AsSingleton(),
ServiceLifetime.Scoped => opts.AsScoped(),
ServiceLifetime.Transient => opts.AsTransient(),
_ => throw new InvalidOperationException(),
};
},
typeof(SomeHandlerClass).Assembly
);
services.AddMessagePipe(
opts =>
{
ServiceLifetime.Singleton => InstanceLifetime.Singleton,
ServiceLifetime.Scoped => InstanceLifetime.Scoped,
ServiceLifetime.Transient => InstanceLifetime.Transient,
_ => throw new InvalidOperationException(),
};
});
opts.InstanceLifetime = ServiceLifetime switch
{
ServiceLifetime.Singleton => InstanceLifetime.Singleton,
ServiceLifetime.Scoped => InstanceLifetime.Scoped,
ServiceLifetime.Transient => InstanceLifetime.Transient,
_ => throw new InvalidOperationException(),
};
}
);

_serviceProvider = services.BuildServiceProvider();
if (ServiceLifetime == ServiceLifetime.Scoped)
Expand Down
54 changes: 31 additions & 23 deletions benchmarks/Mediator.Benchmarks/Request/RequestBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ public sealed record SomeRequest(Guid Id) : IRequest<SomeResponse>, MediatR.IReq

public sealed record SomeResponse(Guid Id);

public sealed class SomeHandlerClass :
IRequestHandler<SomeRequest, SomeResponse>,
MediatR.IRequestHandler<SomeRequest, SomeResponse>,
IAsyncRequestHandler<SomeRequest, SomeResponse>
public sealed class SomeHandlerClass
: IRequestHandler<SomeRequest, SomeResponse>,
MediatR.IRequestHandler<SomeRequest, SomeResponse>,
IAsyncRequestHandler<SomeRequest, SomeResponse>
{
private static readonly SomeResponse _response = new SomeResponse(Guid.NewGuid());

Expand All @@ -22,7 +22,10 @@ public sealed class SomeHandlerClass :

public ValueTask<SomeResponse> Handle(SomeRequest request, CancellationToken cancellationToken) => _vtResponse;

Task<SomeResponse> MediatR.IRequestHandler<SomeRequest, SomeResponse>.Handle(SomeRequest request, CancellationToken cancellationToken) => _tResponse;
Task<SomeResponse> MediatR.IRequestHandler<SomeRequest, SomeResponse>.Handle(
SomeRequest request,
CancellationToken cancellationToken
) => _tResponse;

public ValueTask<SomeResponse> InvokeAsync(SomeRequest request, CancellationToken cancellationToken) => _vtResponse;
}
Expand Down Expand Up @@ -52,26 +55,31 @@ public void Setup()
{
var services = new ServiceCollection();
services.AddMediator(opts => opts.ServiceLifetime = ServiceLifetime);
services.AddMediatR(opts =>
{
_ = ServiceLifetime switch
services.AddMediatR(
opts =>
{
ServiceLifetime.Singleton => opts.AsSingleton(),
ServiceLifetime.Scoped => opts.AsScoped(),
ServiceLifetime.Transient => opts.AsTransient(),
_ => throw new InvalidOperationException(),
};
}, typeof(SomeHandlerClass).Assembly);
services.AddMessagePipe(opts =>
{
opts.InstanceLifetime = ServiceLifetime switch
_ = ServiceLifetime switch
{
ServiceLifetime.Singleton => opts.AsSingleton(),
ServiceLifetime.Scoped => opts.AsScoped(),
ServiceLifetime.Transient => opts.AsTransient(),
_ => throw new InvalidOperationException(),
};
},
typeof(SomeHandlerClass).Assembly
);
services.AddMessagePipe(
opts =>
{
ServiceLifetime.Singleton => InstanceLifetime.Singleton,
ServiceLifetime.Scoped => InstanceLifetime.Scoped,
ServiceLifetime.Transient => InstanceLifetime.Transient,
_ => throw new InvalidOperationException(),
};
});
opts.InstanceLifetime = ServiceLifetime switch
{
ServiceLifetime.Singleton => InstanceLifetime.Singleton,
ServiceLifetime.Scoped => InstanceLifetime.Scoped,
ServiceLifetime.Transient => InstanceLifetime.Transient,
_ => throw new InvalidOperationException(),
};
}
);

_serviceProvider = services.BuildServiceProvider();
if (ServiceLifetime == ServiceLifetime.Scoped)
Expand Down
33 changes: 19 additions & 14 deletions benchmarks/Mediator.Benchmarks/Request/StreamingBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ namespace Mediator.Benchmarks.Request;

public sealed record SomeStreamRequest(Guid Id) : IStreamRequest<SomeResponse>, MediatR.IStreamRequest<SomeResponse>;

public sealed class SomeStreamHandlerClass :
IStreamRequestHandler<SomeStreamRequest, SomeResponse>,
MediatR.IStreamRequestHandler<SomeStreamRequest, SomeResponse>
public sealed class SomeStreamHandlerClass
: IStreamRequestHandler<SomeStreamRequest, SomeResponse>,
MediatR.IStreamRequestHandler<SomeStreamRequest, SomeResponse>
{
private static readonly SomeResponse _response = new SomeResponse(Guid.NewGuid());

Expand All @@ -26,8 +26,10 @@ async IAsyncEnumerable<SomeResponse> _enumerate()
public IAsyncEnumerable<SomeResponse> Handle(SomeStreamRequest request, CancellationToken cancellationToken) =>
_enumerate();

IAsyncEnumerable<SomeResponse> MediatR.IStreamRequestHandler<SomeStreamRequest, SomeResponse>.Handle(SomeStreamRequest request, CancellationToken cancellationToken) =>
_enumerate();
IAsyncEnumerable<SomeResponse> MediatR.IStreamRequestHandler<SomeStreamRequest, SomeResponse>.Handle(
SomeStreamRequest request,
CancellationToken cancellationToken
) => _enumerate();
}

[MemoryDiagnoser]
Expand All @@ -54,16 +56,19 @@ public void Setup()
{
var services = new ServiceCollection();
services.AddMediator(opts => opts.ServiceLifetime = ServiceLifetime);
services.AddMediatR(opts =>
{
_ = ServiceLifetime switch
services.AddMediatR(
opts =>
{
ServiceLifetime.Singleton => opts.AsSingleton(),
ServiceLifetime.Scoped => opts.AsScoped(),
ServiceLifetime.Transient => opts.AsTransient(),
_ => throw new InvalidOperationException(),
};
}, typeof(SomeHandlerClass).Assembly);
_ = ServiceLifetime switch
{
ServiceLifetime.Singleton => opts.AsSingleton(),
ServiceLifetime.Scoped => opts.AsScoped(),
ServiceLifetime.Transient => opts.AsTransient(),
_ => throw new InvalidOperationException(),
};
},
typeof(SomeHandlerClass).Assembly
);

_serviceProvider = services.BuildServiceProvider();
if (ServiceLifetime == ServiceLifetime.Scoped)
Expand Down
61 changes: 38 additions & 23 deletions benchmarks/Mediator.Benchmarks/Request/StructRequestBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,26 @@ public SomeStructRequest(Guid id)
}
}

public sealed class SomeStructHandler : IRequestHandler<SomeStructRequest, SomeResponse>, MediatR.IRequestHandler<SomeStructRequest, SomeResponse>, IAsyncRequestHandler<SomeStructRequest, SomeResponse>
public sealed class SomeStructHandler
: IRequestHandler<SomeStructRequest, SomeResponse>,
MediatR.IRequestHandler<SomeStructRequest, SomeResponse>,
IAsyncRequestHandler<SomeStructRequest, SomeResponse>
{
private static readonly SomeResponse _response = new SomeResponse(Guid.NewGuid());

private static readonly Task<SomeResponse> _tResponse = Task.FromResult(_response);
private static ValueTask<SomeResponse> _vtResponse => new ValueTask<SomeResponse>(_response);

public ValueTask<SomeResponse> Handle(SomeStructRequest request, CancellationToken cancellationToken) => _vtResponse;
public ValueTask<SomeResponse> Handle(SomeStructRequest request, CancellationToken cancellationToken) =>
_vtResponse;

Task<SomeResponse> MediatR.IRequestHandler<SomeStructRequest, SomeResponse>.Handle(SomeStructRequest request, CancellationToken cancellationToken) => _tResponse;
Task<SomeResponse> MediatR.IRequestHandler<SomeStructRequest, SomeResponse>.Handle(
SomeStructRequest request,
CancellationToken cancellationToken
) => _tResponse;

public ValueTask<SomeResponse> InvokeAsync(SomeStructRequest request, CancellationToken cancellationToken) => _vtResponse;
public ValueTask<SomeResponse> InvokeAsync(SomeStructRequest request, CancellationToken cancellationToken) =>
_vtResponse;
}

[MemoryDiagnoser]
Expand Down Expand Up @@ -63,26 +71,31 @@ public void Setup()
{
var services = new ServiceCollection();
services.AddMediator(opts => opts.ServiceLifetime = ServiceLifetime);
services.AddMediatR(opts =>
{
_ = ServiceLifetime switch
services.AddMediatR(
opts =>
{
ServiceLifetime.Singleton => opts.AsSingleton(),
ServiceLifetime.Scoped => opts.AsScoped(),
ServiceLifetime.Transient => opts.AsTransient(),
_ => throw new InvalidOperationException(),
};
}, typeof(SomeHandlerClass).Assembly);
services.AddMessagePipe(opts =>
{
opts.InstanceLifetime = ServiceLifetime switch
_ = ServiceLifetime switch
{
ServiceLifetime.Singleton => opts.AsSingleton(),
ServiceLifetime.Scoped => opts.AsScoped(),
ServiceLifetime.Transient => opts.AsTransient(),
_ => throw new InvalidOperationException(),
};
},
typeof(SomeHandlerClass).Assembly
);
services.AddMessagePipe(
opts =>
{
ServiceLifetime.Singleton => InstanceLifetime.Singleton,
ServiceLifetime.Scoped => InstanceLifetime.Scoped,
ServiceLifetime.Transient => InstanceLifetime.Transient,
_ => throw new InvalidOperationException(),
};
});
opts.InstanceLifetime = ServiceLifetime switch
{
ServiceLifetime.Singleton => InstanceLifetime.Singleton,
ServiceLifetime.Scoped => InstanceLifetime.Scoped,
ServiceLifetime.Transient => InstanceLifetime.Transient,
_ => throw new InvalidOperationException(),
};
}
);

_serviceProvider = services.BuildServiceProvider();
if (ServiceLifetime == ServiceLifetime.Scoped)
Expand All @@ -96,7 +109,9 @@ public void Setup()
_mediator = _serviceProvider.GetRequiredService<IMediator>();
_concreteMediator = _serviceProvider.GetRequiredService<Mediator>();
_mediatr = _serviceProvider.GetRequiredService<MediatR.IMediator>();
_messagePipeHandler = _serviceProvider.GetRequiredService<IAsyncRequestHandler<SomeStructRequest, SomeResponse>>();
_messagePipeHandler = _serviceProvider.GetRequiredService<
IAsyncRequestHandler<SomeStructRequest, SomeResponse>
>();
_handler = _serviceProvider.GetRequiredService<SomeStructHandler>();
_request = new(Guid.NewGuid());
}
Expand Down
1 change: 0 additions & 1 deletion samples/ASPNET/Controllers/WeatherForecastController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace ASPNET.Controllers
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{

private readonly ILogger<WeatherForecastController> _logger;
private readonly IMediator _mediator;

Expand Down
1 change: 1 addition & 0 deletions samples/ASPNET/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Add services to the container.

builder.Services.AddControllers();

// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
Expand Down
Loading

0 comments on commit 57db50d

Please # to comment.