Skip to content

Commit

Permalink
Web API improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardoPires committed Aug 9, 2017
1 parent 095ce0e commit 40501a9
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 831 deletions.
17 changes: 10 additions & 7 deletions Equinox.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.16
VisualStudioVersion = 15.0.26430.13
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{AE3E98DB-35C1-42D8-AB6D-DE37189DDAA1}"
EndProject
Expand All @@ -12,15 +12,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "1 - Presentation", "1 - Presentation", "{9340B0E0-D3D9-4917-B0AA-093A95183265}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "2 - Application", "2 - Application", "{8941C48B-849B-4625-B5F8-0EF567135BC0}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "3 - Application", "3 - Application", "{8941C48B-849B-4625-B5F8-0EF567135BC0}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "3 - Domain", "3 - Domain", "{988F2F26-89C2-4C44-B1BB-42C394832A4E}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "4 - Domain", "4 - Domain", "{988F2F26-89C2-4C44-B1BB-42C394832A4E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "4 - Infra", "4 - Infra", "{04CCC7F8-8AF7-4965-B2EF-2E28331BE421}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "5 - Infra", "5 - Infra", "{04CCC7F8-8AF7-4965-B2EF-2E28331BE421}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "4.1 - Data", "4.1 - Data", "{DCCD4FD6-B437-4586-B932-7AC40EF86A71}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "5.1 - Data", "5.1 - Data", "{DCCD4FD6-B437-4586-B932-7AC40EF86A71}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "4.2 - CrossCutting", "4.2 - CrossCutting", "{68258835-A222-468B-84F5-441AD58BCD51}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "5.2 - CrossCutting", "5.2 - CrossCutting", "{68258835-A222-468B-84F5-441AD58BCD51}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Equinox.UI.Site", "src\Equinox.UI.Site\Equinox.UI.Site.csproj", "{E38E811D-9A10-41EF-A245-907A71C79ACB}"
EndProject
Expand All @@ -40,6 +40,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Equinox.Infra.CrossCutting.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Equinox.WebApi", "src\Equinox.WebApi\Equinox.WebApi.csproj", "{918C9F92-CA9C-4481-9AFA-8DD5A1A810D3}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "2 - Services", "2 - Services", "{A5EBFB52-C5C5-4F98-B441-E48DA9CA5744}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -101,6 +103,7 @@ Global
{9330566C-4093-4FC7-AF61-14850DD15793} = {68258835-A222-468B-84F5-441AD58BCD51}
{A9CB4A5C-DCF4-4F87-83C2-2D6A34C6E2BA} = {988F2F26-89C2-4C44-B1BB-42C394832A4E}
{7C9495CE-AEC5-44CB-9D9C-1150DF99F817} = {68258835-A222-468B-84F5-441AD58BCD51}
{918C9F92-CA9C-4481-9AFA-8DD5A1A810D3} = {9340B0E0-D3D9-4917-B0AA-093A95183265}
{918C9F92-CA9C-4481-9AFA-8DD5A1A810D3} = {A5EBFB52-C5C5-4F98-B441-E48DA9CA5744}
{A5EBFB52-C5C5-4F98-B441-E48DA9CA5744} = {AE3E98DB-35C1-42D8-AB6D-DE37189DDAA1}
EndGlobalSection
EndGlobal
1 change: 1 addition & 0 deletions src/Equinox.Infra.Data/Repository/CustomerRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Equinox.Domain.Interfaces;
using Equinox.Domain.Models;
using Equinox.Infra.Data.Context;
using Microsoft.EntityFrameworkCore;

namespace Equinox.Infra.Data.Repository
{
Expand Down
51 changes: 51 additions & 0 deletions src/Equinox.WebApi/Configurations/RouteConvention.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ApplicationModels;
using Microsoft.AspNetCore.Mvc.Routing;

namespace Equinox.WebApi.Configurations
{
public class RouteConvention : IApplicationModelConvention
{
private readonly AttributeRouteModel _centralPrefix;

public RouteConvention(IRouteTemplateProvider routeTemplateProvider)
{
_centralPrefix = new AttributeRouteModel(routeTemplateProvider);
}

public void Apply(ApplicationModel application)
{
foreach (var controller in application.Controllers)
{
var matchedSelectors = controller.Selectors.Where(x => x.AttributeRouteModel != null).ToList();
if (matchedSelectors.Any())
{
foreach (var selectorModel in matchedSelectors)
{
selectorModel.AttributeRouteModel = AttributeRouteModel.CombineAttributeRouteModel(_centralPrefix,
selectorModel.AttributeRouteModel);
}
}

var unmatchedSelectors = controller.Selectors.Where(x => x.AttributeRouteModel == null).ToList();

if (unmatchedSelectors.Any())
{
foreach (var selectorModel in unmatchedSelectors)
{
selectorModel.AttributeRouteModel = _centralPrefix;
}
}
}
}
}

public static class MvcOptionsExtensions
{
public static void UseCentralRoutePrefix(this MvcOptions opts, IRouteTemplateProvider routeAttribute)
{
opts.Conventions.Insert(0, new RouteConvention(routeAttribute));
}
}
}
Loading

0 comments on commit 40501a9

Please sign in to comment.