diff --git a/Northwind.Application/Northwind.Application.csproj b/Northwind.Application/Northwind.Application.csproj
index 77ece0c1..4b4771fc 100644
--- a/Northwind.Application/Northwind.Application.csproj
+++ b/Northwind.Application/Northwind.Application.csproj
@@ -8,7 +8,7 @@
-
+
diff --git a/Northwind.Domain.Tests/Northwind.Domain.Tests.csproj b/Northwind.Domain.Tests/Northwind.Domain.Tests.csproj
index 47ff293f..74fed439 100644
--- a/Northwind.Domain.Tests/Northwind.Domain.Tests.csproj
+++ b/Northwind.Domain.Tests/Northwind.Domain.Tests.csproj
@@ -7,7 +7,7 @@
-
+
diff --git a/Northwind.Domain.Tests/AdAccountTests.cs b/Northwind.Domain.Tests/ValueObjects/AdAccountTests.cs
similarity index 96%
rename from Northwind.Domain.Tests/AdAccountTests.cs
rename to Northwind.Domain.Tests/ValueObjects/AdAccountTests.cs
index fe99c4ec..1ec1ead5 100644
--- a/Northwind.Domain.Tests/AdAccountTests.cs
+++ b/Northwind.Domain.Tests/ValueObjects/AdAccountTests.cs
@@ -2,7 +2,7 @@
using Northwind.Domain.ValueObjects;
using Xunit;
-namespace Northwind.Domain.Tests
+namespace Northwind.Domain.Tests.ValueObjects
{
public class AdAccountTests
{
diff --git a/Northwind.Domain/ValueObjects/ValueObject.cs b/Northwind.Domain/ValueObjects/ValueObject.cs
index 34d5f580..d96006fd 100644
--- a/Northwind.Domain/ValueObjects/ValueObject.cs
+++ b/Northwind.Domain/ValueObjects/ValueObject.cs
@@ -3,6 +3,7 @@
namespace Northwind.Domain.ValueObjects
{
+ // Source: https://docs.microsoft.com/en-us/dotnet/standard/microservices-architecture/microservice-ddd-cqrs-patterns/implement-value-objects
public abstract class ValueObject
{
protected static bool EqualOperator(ValueObject left, ValueObject right)
diff --git a/Northwind.Web/Controllers/AdminController.cs b/Northwind.Web/Controllers/AdminController.cs
index efbe5950..984b9775 100644
--- a/Northwind.Web/Controllers/AdminController.cs
+++ b/Northwind.Web/Controllers/AdminController.cs
@@ -4,6 +4,7 @@
using Northwind.Application.Employees.Commands;
using Northwind.Application.Employees.Models;
using Northwind.Application.Employees.Queries;
+using Northwind.Web.Infrastructure;
namespace Northwind.Web.Controllers
{
diff --git a/Northwind.Web/Controllers/CategoriesController.cs b/Northwind.Web/Controllers/CategoriesController.cs
index 30155f3d..b3422ecb 100644
--- a/Northwind.Web/Controllers/CategoriesController.cs
+++ b/Northwind.Web/Controllers/CategoriesController.cs
@@ -1,30 +1,23 @@
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
-using MediatR;
using Microsoft.AspNetCore.Mvc;
using Northwind.Application.Categories.Models;
using Northwind.Application.Categories.Queries;
+using Northwind.Web.Infrastructure;
namespace Northwind.Web.Controllers
{
[Route("api/[controller]")]
[ApiController]
- public class CategoriesController : ControllerBase
+ public class CategoriesController : BaseController
{
- private readonly IMediator _mediator;
-
- public CategoriesController(IMediator mediator)
- {
- _mediator = mediator;
- }
-
[HttpGet]
[ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)]
public async Task GetCategoryPreview(
[FromQuery] GetCategoryPreviewQuery query)
{
- return Ok(await _mediator.Send(query));
+ return Ok(await Mediator.Send(query));
}
}
}
diff --git a/Northwind.Web/Controllers/CustomersController.cs b/Northwind.Web/Controllers/CustomersController.cs
index 9841b9a1..e0225b29 100644
--- a/Northwind.Web/Controllers/CustomersController.cs
+++ b/Northwind.Web/Controllers/CustomersController.cs
@@ -4,6 +4,7 @@
using Northwind.Application.Customers.Commands;
using Northwind.Application.Customers.Models;
using Northwind.Application.Customers.Queries;
+using Northwind.Web.Infrastructure;
namespace Northwind.Web.Controllers
{
diff --git a/Northwind.Web/Controllers/ProductsController.cs b/Northwind.Web/Controllers/ProductsController.cs
index a063336c..ef4bf58d 100644
--- a/Northwind.Web/Controllers/ProductsController.cs
+++ b/Northwind.Web/Controllers/ProductsController.cs
@@ -4,6 +4,7 @@
using Northwind.Application.Products.Commands;
using Northwind.Application.Products.Models;
using Northwind.Application.Products.Queries;
+using Northwind.Web.Infrastructure;
namespace Northwind.Web.Controllers
{
diff --git a/Northwind.Web/Controllers/BaseController.cs b/Northwind.Web/Infrastructure/BaseController.cs
similarity index 89%
rename from Northwind.Web/Controllers/BaseController.cs
rename to Northwind.Web/Infrastructure/BaseController.cs
index b7670cb0..effbf66a 100644
--- a/Northwind.Web/Controllers/BaseController.cs
+++ b/Northwind.Web/Infrastructure/BaseController.cs
@@ -2,7 +2,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
-namespace Northwind.Web.Controllers
+namespace Northwind.Web.Infrastructure
{
public abstract class BaseController : Controller
{
diff --git a/Northwind.Web/Northwind.Web.csproj b/Northwind.Web/Northwind.Web.csproj
index 974d1f7e..cb3640d6 100644
--- a/Northwind.Web/Northwind.Web.csproj
+++ b/Northwind.Web/Northwind.Web.csproj
@@ -15,8 +15,9 @@
-
+
+
diff --git a/Northwind.Web/Startup.cs b/Northwind.Web/Startup.cs
index a3d4c302..a83a8ea7 100644
--- a/Northwind.Web/Startup.cs
+++ b/Northwind.Web/Startup.cs
@@ -9,8 +9,10 @@
using Northwind.Web.Infrastructure;
using NSwag.AspNetCore;
using System.Reflection;
+using FluentValidation.AspNetCore;
using MediatR;
using MediatR.Pipeline;
+using Northwind.Application.Customers.Models;
using Northwind.Application.Infrastructure;
using Northwind.Application.Products.Queries;
using Northwind.Persistence;
@@ -31,13 +33,25 @@ public Startup(IConfiguration configuration)
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
+ // Add MediatR
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(RequestPreProcessorBehavior<,>));
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(RequestPerformanceBehaviour<,>));
services.AddMediatR(typeof(GetProductQueryHandler).GetTypeInfo().Assembly);
- services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("NorthwindDatabase")));
+ // Add DbContext using SQL Server Provider
+ services.AddDbContext(options =>
+ options.UseSqlServer(Configuration.GetConnectionString("NorthwindDatabase")));
+ // Add Open API support (will generate specification document)
services.AddSwagger();
+ // Add Logging + Seq
services.AddLogging(loggingBuilder => { loggingBuilder.AddSeq(); });
- services.AddMvc(options => { options.Filters.Add(typeof(CustomExceptionFilterAttribute)); });
+ // Mvc + Custom Excception Filter
+ services
+ .AddMvc(options =>
+ {
+ options.Filters.Add(typeof(CustomExceptionFilterAttribute));
+ })
+ .AddFluentValidation(fv =>
+ fv.RegisterValidatorsFromAssemblyContaining());
}
public void ConfigureContainer(ContainerBuilder builder)