From 8423c8bb636824cc74f543b8443c69211631f09d Mon Sep 17 00:00:00 2001 From: Cesar De la Torre Date: Wed, 15 Mar 2017 18:42:47 -0700 Subject: [PATCH] Larger Refactoring of IntegrationEvents --- .../Basket/Basket.API/Basket.API.csproj | 24 ++-- .../ProductPriceChangedEventHandler.cs} | 8 +- .../Events/ProductPriceChangedEvent.cs.txt | 3 + src/Services/Basket/Basket.API/Startup.cs | 8 +- .../Catalog/Catalog.API/Catalog.API.csproj | 37 +++--- .../Controllers/CatalogController.cs | 12 +- .../Infrastructure/CatalogContext.cs | 8 +- ...factoringToIntegrationEventLog.Designer.cs | 122 ++++++++++++++++++ ...012921_RefactoringToIntegrationEventLog.cs | 53 ++++++++ .../Migrations/CatalogContextModelSnapshot.cs | 9 +- .../AnyFutureIntegrationEventHandler.cs.txt | 3 + .../Events/ProductPriceChangedEvent.cs.txt | 3 + ...Changed.cs => ProductPriceChangedEvent.cs} | 9 +- .../Infrastructure/Data/EventStateEnum.cs | 6 +- ...onEvent.cs => IntegrationEventLogEntry.cs} | 6 +- .../Common/Infrastructure/EventBusRabbitMQ.cs | 6 +- .../Common/Infrastructure/IEventBus.cs | 6 +- .../IIntegrationEventHandler.cs | 2 +- .../Infrastructure/Infrastructure.csproj | 1 + ...rationEventBase.cs => IntegrationEvent.cs} | 4 +- 20 files changed, 262 insertions(+), 68 deletions(-) rename src/Services/Basket/Basket.API/{Events/CatalogPriceChangedHandler.cs => IntegrationEvents/EventHandling/ProductPriceChangedEventHandler.cs} (81%) create mode 100644 src/Services/Basket/Basket.API/IntegrationEvents/Events/ProductPriceChangedEvent.cs.txt create mode 100644 src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20170316012921_RefactoringToIntegrationEventLog.Designer.cs create mode 100644 src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20170316012921_RefactoringToIntegrationEventLog.cs create mode 100644 src/Services/Catalog/Catalog.API/IntegrationEvents/EventHandling/AnyFutureIntegrationEventHandler.cs.txt create mode 100644 src/Services/Catalog/Catalog.API/IntegrationEvents/Events/ProductPriceChangedEvent.cs.txt rename src/Services/Common/Infrastructure/Catalog/{ProductPriceChanged.cs => ProductPriceChangedEvent.cs} (51%) rename src/Services/Common/Infrastructure/Data/{IntegrationEvent.cs => IntegrationEventLogEntry.cs} (82%) rename src/Services/Common/Infrastructure/{IntegrationEventBase.cs => IntegrationEvent.cs} (77%) diff --git a/src/Services/Basket/Basket.API/Basket.API.csproj b/src/Services/Basket/Basket.API/Basket.API.csproj index 1017dbd05..4cea21d4d 100644 --- a/src/Services/Basket/Basket.API/Basket.API.csproj +++ b/src/Services/Basket/Basket.API/Basket.API.csproj @@ -12,6 +12,10 @@ ..\..\..\..\docker-compose.dcproj + + + + PreserveNewest @@ -23,16 +27,16 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/src/Services/Basket/Basket.API/Events/CatalogPriceChangedHandler.cs b/src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/ProductPriceChangedEventHandler.cs similarity index 81% rename from src/Services/Basket/Basket.API/Events/CatalogPriceChangedHandler.cs rename to src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/ProductPriceChangedEventHandler.cs index 678f04ab4..35737e492 100644 --- a/src/Services/Basket/Basket.API/Events/CatalogPriceChangedHandler.cs +++ b/src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/ProductPriceChangedEventHandler.cs @@ -6,17 +6,17 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -namespace Basket.API.Events +namespace Basket.API.IntegrationEvents.EventHandling { - public class ProductPriceChangedHandler : IIntegrationEventHandler + public class ProductPriceChangedEventHandler : IIntegrationEventHandler { private readonly IBasketRepository _repository; - public ProductPriceChangedHandler(IBasketRepository repository) + public ProductPriceChangedEventHandler(IBasketRepository repository) { _repository = repository; } - public async Task Handle(ProductPriceChanged @event) + public async Task Handle(ProductPriceChangedEvent @event) { var userIds = await _repository.GetUsers(); foreach (var id in userIds) diff --git a/src/Services/Basket/Basket.API/IntegrationEvents/Events/ProductPriceChangedEvent.cs.txt b/src/Services/Basket/Basket.API/IntegrationEvents/Events/ProductPriceChangedEvent.cs.txt new file mode 100644 index 000000000..d51583d96 --- /dev/null +++ b/src/Services/Basket/Basket.API/IntegrationEvents/Events/ProductPriceChangedEvent.cs.txt @@ -0,0 +1,3 @@ + + +// To implement ProductPriceChangedEvent.cs here diff --git a/src/Services/Basket/Basket.API/Startup.cs b/src/Services/Basket/Basket.API/Startup.cs index ec5141de3..21a307d21 100644 --- a/src/Services/Basket/Basket.API/Startup.cs +++ b/src/Services/Basket/Basket.API/Startup.cs @@ -15,7 +15,7 @@ using Swashbuckle.Swagger.Model; using Microsoft.eShopOnContainers.Services.Basket.API.Auth.Server; using Microsoft.eShopOnContainers.Services.Common.Infrastructure; using Microsoft.eShopOnContainers.Services.Common.Infrastructure.Catalog; -using Basket.API.Events; +using Basket.API.IntegrationEvents.EventHandling; namespace Microsoft.eShopOnContainers.Services.Basket.API { @@ -79,7 +79,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API }); services.AddTransient(); - services.AddTransient, ProductPriceChangedHandler>(); + services.AddTransient, ProductPriceChangedEventHandler>(); var serviceProvider = services.BuildServiceProvider(); var configuration = serviceProvider.GetRequiredService>().Value; @@ -87,8 +87,8 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API services.AddSingleton(eventBus); - var catalogPriceHandler = serviceProvider.GetService>(); - eventBus.Subscribe(catalogPriceHandler); + var catalogPriceHandler = serviceProvider.GetService>(); + eventBus.Subscribe(catalogPriceHandler); } diff --git a/src/Services/Catalog/Catalog.API/Catalog.API.csproj b/src/Services/Catalog/Catalog.API/Catalog.API.csproj index 387908b90..28bf56d93 100644 --- a/src/Services/Catalog/Catalog.API/Catalog.API.csproj +++ b/src/Services/Catalog/Catalog.API/Catalog.API.csproj @@ -21,6 +21,8 @@ PreserveNewest + + PreserveNewest @@ -28,23 +30,24 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + diff --git a/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs b/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs index 73fae7d5f..bf227d58d 100644 --- a/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs +++ b/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs @@ -149,7 +149,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers _context.CatalogItems.Update(item); await _context.SaveChangesAsync(); - var @event = new ProductPriceChanged(item.Id, item.Price, oldPrice); + var @event = new ProductPriceChangedEvent(item.Id, item.Price, oldPrice); await ProcessEventAsync(@event); } @@ -166,14 +166,14 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers return items; } - private async Task ProcessEventAsync(IntegrationEventBase @event) + private async Task ProcessEventAsync(IntegrationEvent @event) { _eventBus.Publish(@event); - var eventData = new IntegrationEvent(@event); - eventData.TimesSent++; - eventData.State = EventStateEnum.Sent; + var eventLogEntry = new IntegrationEventLogEntry(@event); + eventLogEntry.TimesSent++; + eventLogEntry.State = EventStateEnum.Published; - _context.IntegrationEvents.Add(eventData); + _context.IntegrationEventLog.Add(eventLogEntry); await _context.SaveChangesAsync(); } diff --git a/src/Services/Catalog/Catalog.API/Infrastructure/CatalogContext.cs b/src/Services/Catalog/Catalog.API/Infrastructure/CatalogContext.cs index aac778940..3d1b6716f 100644 --- a/src/Services/Catalog/Catalog.API/Infrastructure/CatalogContext.cs +++ b/src/Services/Catalog/Catalog.API/Infrastructure/CatalogContext.cs @@ -13,14 +13,14 @@ public DbSet CatalogItems { get; set; } public DbSet CatalogBrands { get; set; } public DbSet CatalogTypes { get; set; } - public DbSet IntegrationEvents { get; set; } + public DbSet IntegrationEventLog { get; set; } protected override void OnModelCreating(ModelBuilder builder) { builder.Entity(ConfigureCatalogBrand); builder.Entity(ConfigureCatalogType); builder.Entity(ConfigureCatalogItem); - builder.Entity(ConfigureIntegrationEvent); + builder.Entity(ConfigureIntegrationEventLogEntry); } void ConfigureCatalogItem(EntityTypeBuilder builder) @@ -80,9 +80,9 @@ .HasMaxLength(100); } - void ConfigureIntegrationEvent(EntityTypeBuilder builder) + void ConfigureIntegrationEventLogEntry(EntityTypeBuilder builder) { - builder.ToTable("IntegrationEvent"); + builder.ToTable("IntegrationEventLog"); builder.HasKey(e => e.EventId); diff --git a/src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20170316012921_RefactoringToIntegrationEventLog.Designer.cs b/src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20170316012921_RefactoringToIntegrationEventLog.Designer.cs new file mode 100644 index 000000000..1d9280cfa --- /dev/null +++ b/src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20170316012921_RefactoringToIntegrationEventLog.Designer.cs @@ -0,0 +1,122 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure; +using Microsoft.eShopOnContainers.Services.Common.Infrastructure; + +namespace Catalog.API.Infrastructure.Migrations +{ + [DbContext(typeof(CatalogContext))] + [Migration("20170316012921_RefactoringToIntegrationEventLog")] + partial class RefactoringToIntegrationEventLog + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "1.1.1") + .HasAnnotation("SqlServer:Sequence:.catalog_brand_hilo", "'catalog_brand_hilo', '', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("SqlServer:Sequence:.catalog_hilo", "'catalog_hilo', '', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("SqlServer:Sequence:.catalog_type_hilo", "'catalog_type_hilo', '', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Model.CatalogBrand", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_brand_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("Brand") + .IsRequired() + .HasMaxLength(100); + + b.HasKey("Id"); + + b.ToTable("CatalogBrand"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Model.CatalogItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("CatalogBrandId"); + + b.Property("CatalogTypeId"); + + b.Property("Description"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50); + + b.Property("PictureUri"); + + b.Property("Price"); + + b.HasKey("Id"); + + b.HasIndex("CatalogBrandId"); + + b.HasIndex("CatalogTypeId"); + + b.ToTable("Catalog"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Model.CatalogType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_type_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("Type") + .IsRequired() + .HasMaxLength(100); + + b.HasKey("Id"); + + b.ToTable("CatalogType"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Common.Infrastructure.Data.IntegrationEventLogEntry", b => + { + b.Property("EventId") + .ValueGeneratedOnAdd(); + + b.Property("Content") + .IsRequired(); + + b.Property("CreationTime"); + + b.Property("EventTypeName") + .IsRequired(); + + b.Property("State"); + + b.Property("TimesSent"); + + b.HasKey("EventId"); + + b.ToTable("IntegrationEventLog"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Model.CatalogItem", b => + { + b.HasOne("Microsoft.eShopOnContainers.Services.Catalog.API.Model.CatalogBrand", "CatalogBrand") + .WithMany() + .HasForeignKey("CatalogBrandId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Microsoft.eShopOnContainers.Services.Catalog.API.Model.CatalogType", "CatalogType") + .WithMany() + .HasForeignKey("CatalogTypeId") + .OnDelete(DeleteBehavior.Cascade); + }); + } + } +} diff --git a/src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20170316012921_RefactoringToIntegrationEventLog.cs b/src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20170316012921_RefactoringToIntegrationEventLog.cs new file mode 100644 index 000000000..17c4b2bbc --- /dev/null +++ b/src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20170316012921_RefactoringToIntegrationEventLog.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Catalog.API.Infrastructure.Migrations +{ + public partial class RefactoringToIntegrationEventLog : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "IntegrationEvent"); + + migrationBuilder.CreateTable( + name: "IntegrationEventLog", + columns: table => new + { + EventId = table.Column(nullable: false), + Content = table.Column(nullable: false), + CreationTime = table.Column(nullable: false), + EventTypeName = table.Column(nullable: false), + State = table.Column(nullable: false), + TimesSent = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_IntegrationEventLog", x => x.EventId); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "IntegrationEventLog"); + + migrationBuilder.CreateTable( + name: "IntegrationEvent", + columns: table => new + { + EventId = table.Column(nullable: false), + Content = table.Column(nullable: false), + CreationTime = table.Column(nullable: false), + EventTypeName = table.Column(maxLength: 200, nullable: false), + State = table.Column(nullable: false), + TimesSent = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_IntegrationEvent", x => x.EventId); + }); + } + } +} diff --git a/src/Services/Catalog/Catalog.API/Infrastructure/Migrations/CatalogContextModelSnapshot.cs b/src/Services/Catalog/Catalog.API/Infrastructure/Migrations/CatalogContextModelSnapshot.cs index 4ea056e0d..f6cdb763a 100644 --- a/src/Services/Catalog/Catalog.API/Infrastructure/Migrations/CatalogContextModelSnapshot.cs +++ b/src/Services/Catalog/Catalog.API/Infrastructure/Migrations/CatalogContextModelSnapshot.cs @@ -14,7 +14,7 @@ namespace Catalog.API.Infrastructure.Migrations protected override void BuildModel(ModelBuilder modelBuilder) { modelBuilder - .HasAnnotation("ProductVersion", "1.1.0-rtm-22752") + .HasAnnotation("ProductVersion", "1.1.1") .HasAnnotation("SqlServer:Sequence:.catalog_brand_hilo", "'catalog_brand_hilo', '', '1', '10', '', '', 'Int64', 'False'") .HasAnnotation("SqlServer:Sequence:.catalog_hilo", "'catalog_hilo', '', '1', '10', '', '', 'Int64', 'False'") .HasAnnotation("SqlServer:Sequence:.catalog_type_hilo", "'catalog_type_hilo', '', '1', '10', '', '', 'Int64', 'False'") @@ -82,7 +82,7 @@ namespace Catalog.API.Infrastructure.Migrations b.ToTable("CatalogType"); }); - modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Common.Infrastructure.Data.IntegrationEvent", b => + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Common.Infrastructure.Data.IntegrationEventLogEntry", b => { b.Property("EventId") .ValueGeneratedOnAdd(); @@ -93,8 +93,7 @@ namespace Catalog.API.Infrastructure.Migrations b.Property("CreationTime"); b.Property("EventTypeName") - .IsRequired() - .HasMaxLength(200); + .IsRequired(); b.Property("State"); @@ -102,7 +101,7 @@ namespace Catalog.API.Infrastructure.Migrations b.HasKey("EventId"); - b.ToTable("IntegrationEvent"); + b.ToTable("IntegrationEventLog"); }); modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Model.CatalogItem", b => diff --git a/src/Services/Catalog/Catalog.API/IntegrationEvents/EventHandling/AnyFutureIntegrationEventHandler.cs.txt b/src/Services/Catalog/Catalog.API/IntegrationEvents/EventHandling/AnyFutureIntegrationEventHandler.cs.txt new file mode 100644 index 000000000..d51583d96 --- /dev/null +++ b/src/Services/Catalog/Catalog.API/IntegrationEvents/EventHandling/AnyFutureIntegrationEventHandler.cs.txt @@ -0,0 +1,3 @@ + + +// To implement ProductPriceChangedEvent.cs here diff --git a/src/Services/Catalog/Catalog.API/IntegrationEvents/Events/ProductPriceChangedEvent.cs.txt b/src/Services/Catalog/Catalog.API/IntegrationEvents/Events/ProductPriceChangedEvent.cs.txt new file mode 100644 index 000000000..4ace69180 --- /dev/null +++ b/src/Services/Catalog/Catalog.API/IntegrationEvents/Events/ProductPriceChangedEvent.cs.txt @@ -0,0 +1,3 @@ + + +// To implement any future integration event handler here diff --git a/src/Services/Common/Infrastructure/Catalog/ProductPriceChanged.cs b/src/Services/Common/Infrastructure/Catalog/ProductPriceChangedEvent.cs similarity index 51% rename from src/Services/Common/Infrastructure/Catalog/ProductPriceChanged.cs rename to src/Services/Common/Infrastructure/Catalog/ProductPriceChangedEvent.cs index 0610a0e59..70907bc16 100644 --- a/src/Services/Common/Infrastructure/Catalog/ProductPriceChanged.cs +++ b/src/Services/Common/Infrastructure/Catalog/ProductPriceChangedEvent.cs @@ -4,7 +4,10 @@ using System.Text; namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure.Catalog { - public class ProductPriceChanged : IntegrationEventBase + // Integration Events notes: + // An Event is “something that has happened in the past”, therefore its name has to be + // An Integration Event is an event that can cause side effects to other microsrvices, Bounded-Contexts or external systems. + public class ProductPriceChangedEvent : IntegrationEvent { public int ProductId { get; private set; } @@ -12,11 +15,11 @@ namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure.Catalog public decimal OldPrice { get; private set; } - public ProductPriceChanged(int productId, decimal newPrice, decimal oldPrice) + public ProductPriceChangedEvent(int productId, decimal newPrice, decimal oldPrice) { ProductId = productId; NewPrice = newPrice; OldPrice = oldPrice; } -} + } } diff --git a/src/Services/Common/Infrastructure/Data/EventStateEnum.cs b/src/Services/Common/Infrastructure/Data/EventStateEnum.cs index e952b7742..47142dc07 100644 --- a/src/Services/Common/Infrastructure/Data/EventStateEnum.cs +++ b/src/Services/Common/Infrastructure/Data/EventStateEnum.cs @@ -6,8 +6,8 @@ namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure { public enum EventStateEnum { - NotSend = 0, - Sent = 1, - SendingFailed = 2 + NotPublished = 0, + Published = 1, + PublishedFailed = 2 } } diff --git a/src/Services/Common/Infrastructure/Data/IntegrationEvent.cs b/src/Services/Common/Infrastructure/Data/IntegrationEventLogEntry.cs similarity index 82% rename from src/Services/Common/Infrastructure/Data/IntegrationEvent.cs rename to src/Services/Common/Infrastructure/Data/IntegrationEventLogEntry.cs index 97b313021..ff4c190d0 100644 --- a/src/Services/Common/Infrastructure/Data/IntegrationEvent.cs +++ b/src/Services/Common/Infrastructure/Data/IntegrationEventLogEntry.cs @@ -5,15 +5,15 @@ using Newtonsoft.Json; namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure.Data { - public class IntegrationEvent + public class IntegrationEventLogEntry { - public IntegrationEvent(IntegrationEventBase @event) + public IntegrationEventLogEntry(IntegrationEvent @event) { EventId = @event.Id; CreationTime = DateTime.UtcNow; EventTypeName = @event.GetType().FullName; Content = JsonConvert.SerializeObject(@event); - State = EventStateEnum.NotSend; + State = EventStateEnum.NotPublished; TimesSent = 0; } public Guid EventId { get; private set; } diff --git a/src/Services/Common/Infrastructure/EventBusRabbitMQ.cs b/src/Services/Common/Infrastructure/EventBusRabbitMQ.cs index f9c3d6a57..4a6cdb0c2 100644 --- a/src/Services/Common/Infrastructure/EventBusRabbitMQ.cs +++ b/src/Services/Common/Infrastructure/EventBusRabbitMQ.cs @@ -30,7 +30,7 @@ namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure _handlers = new Dictionary>(); _eventTypes = new List(); } - public void Publish(IntegrationEventBase @event) + public void Publish(IntegrationEvent @event) { var eventName = @event.GetType().Name; var factory = new ConnectionFactory() { HostName = _connectionString }; @@ -51,7 +51,7 @@ namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure } - public void Subscribe(IIntegrationEventHandler handler) where T : IntegrationEventBase + public void Subscribe(IIntegrationEventHandler handler) where T : IntegrationEvent { var eventName = typeof(T).Name; if (_handlers.ContainsKey(eventName)) @@ -72,7 +72,7 @@ namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure } - public void Unsubscribe(IIntegrationEventHandler handler) where T : IntegrationEventBase + public void Unsubscribe(IIntegrationEventHandler handler) where T : IntegrationEvent { var eventName = typeof(T).Name; if (_handlers.ContainsKey(eventName) && _handlers[eventName].Contains(handler)) diff --git a/src/Services/Common/Infrastructure/IEventBus.cs b/src/Services/Common/Infrastructure/IEventBus.cs index 483e550ec..4a8e75a2c 100644 --- a/src/Services/Common/Infrastructure/IEventBus.cs +++ b/src/Services/Common/Infrastructure/IEventBus.cs @@ -6,8 +6,8 @@ namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure { public interface IEventBus { - void Subscribe(IIntegrationEventHandler handler) where T: IntegrationEventBase; - void Unsubscribe(IIntegrationEventHandler handler) where T : IntegrationEventBase; - void Publish(IntegrationEventBase @event); + void Subscribe(IIntegrationEventHandler handler) where T: IntegrationEvent; + void Unsubscribe(IIntegrationEventHandler handler) where T : IntegrationEvent; + void Publish(IntegrationEvent @event); } } diff --git a/src/Services/Common/Infrastructure/IIntegrationEventHandler.cs b/src/Services/Common/Infrastructure/IIntegrationEventHandler.cs index f4c00fa6b..72dd2d04b 100644 --- a/src/Services/Common/Infrastructure/IIntegrationEventHandler.cs +++ b/src/Services/Common/Infrastructure/IIntegrationEventHandler.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure { public interface IIntegrationEventHandler : IIntegrationEventHandler - where TIntegrationEvent: IntegrationEventBase + where TIntegrationEvent: IntegrationEvent { Task Handle(TIntegrationEvent @event); } diff --git a/src/Services/Common/Infrastructure/Infrastructure.csproj b/src/Services/Common/Infrastructure/Infrastructure.csproj index 34f8bc5d5..a776b1a13 100644 --- a/src/Services/Common/Infrastructure/Infrastructure.csproj +++ b/src/Services/Common/Infrastructure/Infrastructure.csproj @@ -5,6 +5,7 @@ Microsoft.eShopOnContainers.Services.Common.Infrastructure + diff --git a/src/Services/Common/Infrastructure/IntegrationEventBase.cs b/src/Services/Common/Infrastructure/IntegrationEvent.cs similarity index 77% rename from src/Services/Common/Infrastructure/IntegrationEventBase.cs rename to src/Services/Common/Infrastructure/IntegrationEvent.cs index b11c17815..2ac021784 100644 --- a/src/Services/Common/Infrastructure/IntegrationEventBase.cs +++ b/src/Services/Common/Infrastructure/IntegrationEvent.cs @@ -4,9 +4,9 @@ using System.Text; namespace Microsoft.eShopOnContainers.Services.Common.Infrastructure { - public class IntegrationEventBase + public class IntegrationEvent { - public IntegrationEventBase() + public IntegrationEvent() { Id = Guid.NewGuid(); }