From 930ebfc30a2d5a6f02891c5b18180b92ae302d5e Mon Sep 17 00:00:00 2001 From: Jason Taylor Date: Fri, 2 Nov 2018 14:19:26 +1000 Subject: [PATCH] Fixed issue "Failing to instantiate CreateCustomerCommandHandler" --- .../Interfaces/INotificationService.cs | 3 ++- .../NotificationService.cs | 5 +++-- .../Infrastructure/AutofacModule.cs | 21 ------------------- Northwind.WebUI/Startup.cs | 8 +++++-- 4 files changed, 11 insertions(+), 26 deletions(-) delete mode 100644 Northwind.WebUI/Infrastructure/AutofacModule.cs diff --git a/Northwind.Application/Interfaces/INotificationService.cs b/Northwind.Application/Interfaces/INotificationService.cs index 25cb2834..05fc70ed 100644 --- a/Northwind.Application/Interfaces/INotificationService.cs +++ b/Northwind.Application/Interfaces/INotificationService.cs @@ -1,9 +1,10 @@ using Northwind.Application.Notifications.Models; +using System.Threading.Tasks; namespace Northwind.Application.Interfaces { public interface INotificationService { - void Send(Message message); + Task SendAsync(Message message); } } diff --git a/Northwind.Infrastructure/NotificationService.cs b/Northwind.Infrastructure/NotificationService.cs index 97dc5bde..5bf18041 100644 --- a/Northwind.Infrastructure/NotificationService.cs +++ b/Northwind.Infrastructure/NotificationService.cs @@ -1,13 +1,14 @@ using Northwind.Application.Interfaces; using Northwind.Application.Notifications.Models; +using System.Threading.Tasks; namespace Northwind.Infrastructure { public class NotificationService : INotificationService { - public void Send(Message message) + public Task SendAsync(Message message) { - // Do nothing + return Task.CompletedTask; } } } diff --git a/Northwind.WebUI/Infrastructure/AutofacModule.cs b/Northwind.WebUI/Infrastructure/AutofacModule.cs deleted file mode 100644 index 7b10a82f..00000000 --- a/Northwind.WebUI/Infrastructure/AutofacModule.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Autofac; -using Northwind.Application.Customers.Queries.GetCustomersList; -using Northwind.Application.Interfaces; -using Northwind.Common; -using Northwind.Infrastructure; - -namespace Northwind.WebUI.Infrastructure -{ - public class AutofacModule : Module - { - protected override void Load(ContainerBuilder builder) - { - builder.RegisterAssemblyTypes(typeof(GetCustomersListQueryHandler).Assembly) - .Where(x => x.Name.EndsWith("Command") || x.Name.EndsWith("Query") || x.Name.EndsWith("Service")) - .AsImplementedInterfaces(); - - builder.RegisterType().As(); - builder.RegisterType().As(); - } - } -} \ No newline at end of file diff --git a/Northwind.WebUI/Startup.cs b/Northwind.WebUI/Startup.cs index 38062a20..f28324cb 100644 --- a/Northwind.WebUI/Startup.cs +++ b/Northwind.WebUI/Startup.cs @@ -4,13 +4,15 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.SpaServices.AngularCli; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Northwind.Application.Customers.Commands.CreateCustomer; using Northwind.Application.Infrastructure; +using Northwind.Application.Interfaces; using Northwind.Application.Products.Queries.GetProduct; +using Northwind.Common; +using Northwind.Infrastructure; using Northwind.Persistence; using Northwind.WebUI.Filters; using NSwag.AspNetCore; @@ -31,6 +33,9 @@ public Startup(IConfiguration configuration) public void ConfigureServices(IServiceCollection services) { // Add framework services. + services.AddTransient(); + services.AddTransient(); + // Add MediatR services.AddTransient(typeof(IPipelineBehavior<,>), typeof(RequestPreProcessorBehavior<,>)); services.AddTransient(typeof(IPipelineBehavior<,>), typeof(RequestPerformanceBehaviour<,>)); @@ -41,7 +46,6 @@ public void ConfigureServices(IServiceCollection services) services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("NorthwindDatabase"))); - services .AddMvc(options => options.Filters.Add(typeof(CustomExceptionFilterAttribute))) .SetCompatibilityVersion(CompatibilityVersion.Version_2_1)