Adding RateLimit Feature ...
This commit is contained in:
@@ -14,6 +14,7 @@ using Swashbuckle.AspNetCore.SwaggerUI;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using xExceptions.Constants;
|
||||
|
||||
namespace xCommons.Extensions
|
||||
{
|
||||
@@ -39,7 +40,7 @@ namespace xCommons.Extensions
|
||||
/// <param name="configuration"></param>
|
||||
/// <param name="environment"></param>
|
||||
public static void AddXAppConfiguration(
|
||||
this IServiceCollection services,
|
||||
this IServiceCollection services,
|
||||
IConfiguration configuration,
|
||||
string environment = null
|
||||
)
|
||||
@@ -52,6 +53,41 @@ namespace xCommons.Extensions
|
||||
services.AddSingleton(appConfiguration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve Rate Limit Configurations and Register it ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="configuration"></param>
|
||||
public static void AddXRateLimitConfiguration(
|
||||
this IServiceCollection source,
|
||||
IConfiguration configuration
|
||||
)
|
||||
{
|
||||
//
|
||||
var config = configuration.GetXRateLimitConfiguration();
|
||||
source.AddXRateLimitConfiguration(config);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register Rate Limit Configuration ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="configuration"></param>
|
||||
public static void AddXRateLimitConfiguration(
|
||||
this IServiceCollection source,
|
||||
XRateLimitConfiguration configuration
|
||||
)
|
||||
{
|
||||
//
|
||||
if (source.IsNull())
|
||||
{
|
||||
XException.InvalidConfiguration.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
source.AddSingleton(configuration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add Environment name to XAppConfiguration ...
|
||||
/// </summary>
|
||||
@@ -74,7 +110,7 @@ namespace xCommons.Extensions
|
||||
{
|
||||
appConfiguration.Environment = environmentName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -509,6 +545,56 @@ namespace xCommons.Extensions
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register RateLimit Service ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
public static void AddXRateLimit(
|
||||
this IServiceCollection source
|
||||
)
|
||||
{
|
||||
//
|
||||
source.AddMemoryCache();
|
||||
source.AddSingleton<IXRateLimitProvider, XRateLimitProvider>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register RateLimit Service ...
|
||||
/// Configs Retrieved from AppSettings ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="configuration"></param>
|
||||
public static void AddXRateLimit(
|
||||
this IServiceCollection source,
|
||||
IConfiguration configuration
|
||||
)
|
||||
{
|
||||
//
|
||||
var config = configuration.GetXRateLimitConfiguration();
|
||||
source.AddXRateLimit(config);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register RateLimit Service ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="configuration"></param>
|
||||
public static void AddXRateLimit(
|
||||
this IServiceCollection source,
|
||||
XRateLimitConfiguration configuration
|
||||
)
|
||||
{
|
||||
//
|
||||
if (configuration.IsNull())
|
||||
{
|
||||
XException.InvalidConfiguration.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
source.AddXRateLimitConfiguration(configuration);
|
||||
source.AddXRateLimit();
|
||||
}
|
||||
|
||||
public static void AddXFileTypeDetector(
|
||||
this IServiceCollection source,
|
||||
IConfiguration configuration
|
||||
|
||||
Reference in New Issue
Block a user