mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-27 09:32:51 +08:00

* copied everything from repos back to ocelot repo * added src projects to sln * removed all test projects that have no tests * added all test projects to sln * removed test not on master * merged unit tests * merged acceptance tests * merged integration tests * fixed namepaces * build script creates packages for all projects * updated docs to make sure no references to external repos that we will remove * +semver: breaking
39 lines
1.3 KiB
C#
39 lines
1.3 KiB
C#
namespace Ocelot.Provider.Polly
|
|
{
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
using Configuration;
|
|
using DependencyInjection;
|
|
using Errors;
|
|
using global::Polly.CircuitBreaker;
|
|
using global::Polly.Timeout;
|
|
using Logging;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Requester;
|
|
|
|
public static class OcelotBuilderExtensions
|
|
{
|
|
public static IOcelotBuilder AddPolly(this IOcelotBuilder builder)
|
|
{
|
|
var errorMapping = new Dictionary<Type, Func<Exception, Error>>
|
|
{
|
|
{typeof(TaskCanceledException), e => new RequestTimedOutError(e)},
|
|
{typeof(TimeoutRejectedException), e => new RequestTimedOutError(e)},
|
|
{typeof(BrokenCircuitException), e => new RequestTimedOutError(e)}
|
|
};
|
|
|
|
builder.Services.AddSingleton(errorMapping);
|
|
|
|
DelegatingHandler QosDelegatingHandlerDelegate(DownstreamReRoute reRoute, IOcelotLoggerFactory logger)
|
|
{
|
|
return new PollyCircuitBreakingDelegatingHandler(new PollyQoSProvider(reRoute, logger), logger);
|
|
}
|
|
|
|
builder.Services.AddSingleton((QosDelegatingHandlerDelegate) QosDelegatingHandlerDelegate);
|
|
return builder;
|
|
}
|
|
}
|
|
}
|