Skip to content

Instantly share code, notes, and snippets.

View GeradeDev's full-sized avatar
🖖
Merging without reviewing.

Gerade Geldenhuys GeradeDev

🖖
Merging without reviewing.
View GitHub Profile
public class RabbitMqTriggerBinding : ITriggerBinding
{
private readonly ILogger _logger;
public Type TriggerValueType => typeof(BasicDeliverEventArgs);
public IReadOnlyDictionary<string, Type> BindingDataContract => new Dictionary<string, Type>();
private readonly ParameterInfo _parameter;
public class RabbitMqTriggerListener : IListener
{
private readonly ITriggeredFunctionExecutor _executor;
private readonly RabbitMqTriggerAttribute _attribute;
IModel _model { get; }
IBasicPublishBatch _createBasicPublishBatch => CreateBasicPublishBatch();
private string _connectionString;
private string _hostName;
private string _queueName;
[Binding]
[AttributeUsage(AttributeTargets.Parameter)]
public class RabbitMqTriggerAttribute : Attribute
{
public string HostName { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public string Port { get; set; }
public string Connection { get; set; }
[HttpGet("{customerid}")]
[Cached(Constants.Day_In_Seconds)]
public async Task<IActionResult> GetCustomerBasket(Guid customerid)
{
var basket = await _consulHttpClient.GetAsync<BasketDto>("basket-service", $"/basket/{customerid}");
return Ok(basket);
}
public class ConsulHttpClient : IConsulHttpClient
{
private readonly HttpClient _client;
private IConsulClient _consulclient;
public ConsulHttpClient(HttpClient client, IConsulClient consulclient)
{
_client = client;
_consulclient = consulclient;
}
public static IServiceCollection AddConsul(this IServiceCollection serviceCollection)
{
IConfiguration configuration;
using (var serviceProvider = serviceCollection.BuildServiceProvider())
{
configuration = serviceProvider.GetService<IConfiguration>();
}
ConsulOptions consulConfigOptions = configuration.GetOptions<ConsulOptions>("Consul");
serviceCollection.Configure<ConsulOptions>(configuration.GetSection("Consul"));
COPY *.csproj .
RUN dotnet restore
# Copy everything else and build
COPY . .
RUN dotnet publish -c Release -o out
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public class CachedAttribute : Attribute, IAsyncActionFilter
{
private readonly int _timeToLiveSeconds;
public CachedAttribute(int timeToLiveSeconds)
{
_timeToLiveSeconds = timeToLiveSeconds;
}
public class ResponseCacheService : IResponseCacheService
{
private readonly IDistributedCache _distributedCache;
public ResponseCacheService(IDistributedCache distributedCache)
{
_distributedCache = distributedCache;
}
public async Task CacheResponseAsync(string cacheKey, object response, TimeSpan timeTimeLive)
public static IServiceCollection AddRedis(this IServiceCollection services, IConfiguration configuration)
{
var redisCacheSettings = new RedisOptions();
configuration.GetSection(SectionName).Bind(redisCacheSettings);
services.AddSingleton(redisCacheSettings);
if (!redisCacheSettings.Enabled)
{
return services;
}