Skip to content

Instantly share code, notes, and snippets.

// Add all the assemblies to MediatR
services.AddMediatR(typeof(DABBaseRequest).GetTypeInfo().Assembly);
// For all the validators, register them with dependency injection as scoped
AssemblyScanner.FindValidatorsInAssembly(typeof(DABBaseRequest).Assembly)
.ForEach(item => services.AddScoped(item.InterfaceType, item.ValidatorType));
// Add the custome pipeline validation to DI
services.AddScoped(typeof(IPipelineBehavior<,>), typeof(MyCustomPipelineValidationBehavior<,>));
var validator = new DeleteUserRequestValidator();
var result = validator.Validate(request);
if (!result.IsValid)
{
throw new MyCustomValidationException(result.ToString());
}
public class MyCustomPipelineValidationBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> where TRequest : IRequest<TResponse>
{
private readonly IEnumerable<IValidator> _validators;
public MyCustomPipelineValidationBehavior(IEnumerable<IValidator<TRequest>> validators)
{
_validators = validators;
}
public Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
$testResultsFolder = 'TestsCodeCoverage'
$codeCoverageExecutable = '~\.nuget\packages\microsoft.codecoverage\16.6.1\build\netstandard1.0\CodeCoverage\CodeCoverage.exe'
$reportGeneratorDll = '~\.nuget\packages\reportgenerator\4.5.8\tools\netcoreapp3.0\ReportGenerator.dll'
Remove-Item $testResultsFolder -Recurse
dotnet test . --results-directory:$testResultsFolder'\CodeCoverage' --collect:"Code Coverage"
Write-Host 'Code Coverage tests completed' -ForegroundColor Green
$recentCoverageFile = Get-ChildItem -File -Filter *.coverage -Path $testResultsFolder'\CodeCoverage' -Name -Recurse | Select-Object -First 1;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using System.IO;
namespace DAB.Api
{
ALTER TABLE ApiClaims MODIFY COLUMN Id int(11) AUTO_INCREMENT;
ALTER TABLE ApiResources MODIFY COLUMN Id int(11) AUTO_INCREMENT;
ALTER TABLE ApiScopeClaims MODIFY COLUMN Id int(11) AUTO_INCREMENT;
ALTER TABLE ApiScopes MODIFY COLUMN Id int(11) AUTO_INCREMENT;
ALTER TABLE ApiSecrets MODIFY COLUMN Id int(11) AUTO_INCREMENT;
ALTER TABLE ClientClaims MODIFY COLUMN Id int(11) AUTO_INCREMENT;
ALTER TABLE ClientCorsOrigins MODIFY COLUMN Id int(11) AUTO_INCREMENT;
ALTER TABLE ClientGrantTypes MODIFY COLUMN Id int(11) AUTO_INCREMENT;
ALTER TABLE ClientIdPRestrictions MODIFY COLUMN Id int(11) AUTO_INCREMENT;
ALTER TABLE ClientPostLogoutRedirectUris MODIFY COLUMN Id int(11) AUTO_INCREMENT;
Add-Type @"
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32;
namespace Wallpaper
{
public enum Style : int
{
Tile, Center, Stretch, NoChange
}
Ssl2 Authentication failed because the remote party has closed the transport stream.
Ssl3 Authentication failed because the remote party has closed the transport stream.
Default Authentication failed because the remote party has closed the transport stream.
None The specified value is not valid in the 'SslProtocolType' enumeration.
Tls Authentication failed because the remote party has closed the transport stream.
Tls11 The remote certificate is invalid according to the validation procedure.
Tls12 The remote certificate is invalid according to the validation procedure.
@timdows
timdows / RawSqlExecute.cs
Last active July 22, 2016 13:21
RawSqlExecute in ASP.NET Core with EntityFramework Core 1.0
public class RawSqlExecute
{
/// <summary>
/// Plain text sql query to a list that can easaly be transformed to a json object
/// </summary>
/// <param name="dataContext"></param>
/// <param name="sql"></param>
/// <returns>Dynamic list</returns>
public static List<dynamic> GetDynamicResults(
DataContext dataContext,