From f67109805f3da182c93a7d6005d0e4a96bef5c73 Mon Sep 17 00:00:00 2001 From: Renato Golia Date: Sun, 9 Sep 2018 17:56:02 +0200 Subject: [PATCH] Changed Notification to Message (#1) --- .../IMessageHandler.cs | 10 ++++++++++ .../INotificationHandler.cs | 10 ---------- .../ServiceCollectionExtensions.cs | 10 +++++----- .../SqsEventHandler.cs | 14 +++++++------- 4 files changed, 22 insertions(+), 22 deletions(-) create mode 100644 src/Kralizek.Lambda.Template.Sqs/IMessageHandler.cs delete mode 100644 src/Kralizek.Lambda.Template.Sqs/INotificationHandler.cs diff --git a/src/Kralizek.Lambda.Template.Sqs/IMessageHandler.cs b/src/Kralizek.Lambda.Template.Sqs/IMessageHandler.cs new file mode 100644 index 0000000..65d5660 --- /dev/null +++ b/src/Kralizek.Lambda.Template.Sqs/IMessageHandler.cs @@ -0,0 +1,10 @@ +using System.Threading.Tasks; +using Amazon.Lambda.Core; + +namespace Kralizek.Lambda +{ + public interface IMessageHandler where TMessage : class + { + Task HandleAsync(TMessage message, ILambdaContext context); + } +} diff --git a/src/Kralizek.Lambda.Template.Sqs/INotificationHandler.cs b/src/Kralizek.Lambda.Template.Sqs/INotificationHandler.cs deleted file mode 100644 index 9054ebf..0000000 --- a/src/Kralizek.Lambda.Template.Sqs/INotificationHandler.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Threading.Tasks; -using Amazon.Lambda.Core; - -namespace Kralizek.Lambda -{ - public interface INotificationHandler where TNotification : class - { - Task HandleAsync(TNotification notification, ILambdaContext context); - } -} diff --git a/src/Kralizek.Lambda.Template.Sqs/ServiceCollectionExtensions.cs b/src/Kralizek.Lambda.Template.Sqs/ServiceCollectionExtensions.cs index 3c37878..a69d30a 100644 --- a/src/Kralizek.Lambda.Template.Sqs/ServiceCollectionExtensions.cs +++ b/src/Kralizek.Lambda.Template.Sqs/ServiceCollectionExtensions.cs @@ -5,13 +5,13 @@ namespace Kralizek.Lambda { public static class ServiceCollectionExtensions { - public static IServiceCollection UseSqsHandler(this IServiceCollection services) - where TNotification : class - where THandler : class, INotificationHandler + public static IServiceCollection UseSqsHandler(this IServiceCollection services) + where TMessage : class + where THandler : class, IMessageHandler { - services.AddTransient, SqsEventHandler>(); + services.AddTransient, SqsEventHandler>(); - services.AddTransient, THandler>(); + services.AddTransient, THandler>(); return services; } diff --git a/src/Kralizek.Lambda.Template.Sqs/SqsEventHandler.cs b/src/Kralizek.Lambda.Template.Sqs/SqsEventHandler.cs index 64ee7b6..6fbb85c 100644 --- a/src/Kralizek.Lambda.Template.Sqs/SqsEventHandler.cs +++ b/src/Kralizek.Lambda.Template.Sqs/SqsEventHandler.cs @@ -8,7 +8,7 @@ namespace Kralizek.Lambda { - public class SqsEventHandler : IEventHandler where TNotification : class + public class SqsEventHandler : IEventHandler where TMessage : class { private readonly ILogger _logger; private readonly IServiceProvider _serviceProvider; @@ -25,19 +25,19 @@ public async Task HandleAsync(SQSEvent input, ILambdaContext context) { using (_serviceProvider.CreateScope()) { - var message = record.Body; - var notification = JsonConvert.DeserializeObject(message); + var sqsMessage = record.Body; + var message = JsonConvert.DeserializeObject(sqsMessage); - var handler = _serviceProvider.GetService>(); + var handler = _serviceProvider.GetService>(); if (handler == null) { - _logger.LogCritical($"No INotificationHandler<{typeof(TNotification).Name}> could be found."); - throw new InvalidOperationException($"No INotificationHandler<{typeof(TNotification).Name}> could be found."); + _logger.LogCritical($"No IMessageHandler<{typeof(TMessage).Name}> could be found."); + throw new InvalidOperationException($"No IMessageHandler<{typeof(TMessage).Name}> could be found."); } _logger.LogInformation("Invoking notification handler"); - await handler.HandleAsync(notification, context); + await handler.HandleAsync(message, context); } } }