Skip to content

Commit

Permalink
Refactoring. Updating dependencies. Wiring up FluentValidation.
Browse files Browse the repository at this point in the history
  • Loading branch information
jasontaylordev committed Jun 13, 2018
1 parent 57a991a commit ad8b975
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Northwind.Application/Northwind.Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="Dapper" Version="1.50.5" />
<PackageReference Include="FluentValidation" Version="7.6.100" />
<PackageReference Include="FluentValidation" Version="7.6.101" />
<PackageReference Include="MediatR" Version="5.0.1" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion Northwind.Domain.Tests/Northwind.Domain.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Northwind.Domain.ValueObjects;
using Xunit;

namespace Northwind.Domain.Tests
namespace Northwind.Domain.Tests.ValueObjects
{
public class AdAccountTests
{
Expand Down
1 change: 1 addition & 0 deletions Northwind.Domain/ValueObjects/ValueObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions Northwind.Web/Controllers/AdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
13 changes: 3 additions & 10 deletions Northwind.Web/Controllers/CategoriesController.cs
Original file line number Diff line number Diff line change
@@ -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<CategoryPreviewDto>), (int)HttpStatusCode.OK)]
public async Task<IActionResult> GetCategoryPreview(
[FromQuery] GetCategoryPreviewQuery query)
{
return Ok(await _mediator.Send(query));
return Ok(await Mediator.Send(query));
}
}
}
1 change: 1 addition & 0 deletions Northwind.Web/Controllers/CustomersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
1 change: 1 addition & 0 deletions Northwind.Web/Controllers/ProductsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
3 changes: 2 additions & 1 deletion Northwind.Web/Northwind.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.2.2" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.0" />
<PackageReference Include="NSwag.AspNetCore" Version="11.17.13" />
<PackageReference Include="NSwag.AspNetCore" Version="11.17.14" />
<PackageReference Include="Seq.Extensions.Logging" Version="4.0.0" />
<PackageReference Include="FluentValidation.AspNetCore" Version="7.6.101" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Northwind.Application\Northwind.Application.csproj" />
Expand Down
18 changes: 16 additions & 2 deletions Northwind.Web/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<NorthwindDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("NorthwindDatabase")));
// Add DbContext using SQL Server Provider
services.AddDbContext<NorthwindDbContext>(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<CustomerDetailModel>());
}

public void ConfigureContainer(ContainerBuilder builder)
Expand Down

0 comments on commit ad8b975

Please sign in to comment.