diff --git a/LaaProductionWeb/LaaProductionWeb.sln b/LaaProductionWeb/LaaProductionWeb.sln index 912cbeb5..8ccc405d 100644 --- a/LaaProductionWeb/LaaProductionWeb.sln +++ b/LaaProductionWeb/LaaProductionWeb.sln @@ -9,6 +9,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaaProductionWeb.Data", "La EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaaProductionWeb.Services", "LaaProductionWeb.Services\LaaProductionWeb.Services.csproj", "{FF167011-431A-41A7-A7DB-560E08860388}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Documents", "Documents", "{59875741-02AA-4D9A-9B3C-683CA6DDBE7B}" + ProjectSection(SolutionItems) = preProject + ..\..\..\..\Downloads\SRS Wildcard Order Info Search.docx = ..\..\..\..\Downloads\SRS Wildcard Order Info Search.docx + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/APIControllerFactory.cs b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/APIControllerFactory.cs deleted file mode 100644 index bb76a079..00000000 --- a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/APIControllerFactory.cs +++ /dev/null @@ -1,54 +0,0 @@ -namespace LaaProductionWeb.App_Infrastructure -{ - using System; - using System.Collections.Generic; - using System.Net.Http; - using System.Web.Http; - using System.Web.Http.Controllers; - using System.Web.Http.Dispatcher; - - public class APIControllerActivator : IHttpControllerActivator - { - private readonly IServiceProvider serviceProvider; - - public APIControllerActivator(IServiceProvider serviceProvider) - => this.serviceProvider = serviceProvider; - - public IHttpController Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType) - => this.serviceProvider.GetService(controllerType) as IHttpController; - } - - public class APIControllerFactory : IHttpControllerSelector - { - public HttpControllerDescriptor SelectController(HttpRequestMessage request) - { - var routeData = request.GetRouteData(); - var controllerName = default(string); - var controllerType = default(Type); - - if (routeData.Values.TryGetValue("controller", out object controllerValue)) - { - controllerName = $"{controllerValue}Controller"; - } - - if (routeData.Values.TryGetValue("area", out object area)) - { - controllerType = Type.GetType($"LaaProductionWeb.Areas.{area}.Rest.{controllerName}", false, true); - } - else - { - controllerType = Type.GetType($"LaaProductionWeb.Rest.{controllerName}", false, true); - } - - return new HttpControllerDescriptor() - { - ControllerName = controllerName, - ControllerType = controllerType, - Configuration = GlobalConfiguration.Configuration - }; - } - - public IDictionary GetControllerMapping() - => new Dictionary(); - } -} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/ControllersExtensions.cs b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/ControllersExtensions.cs index f2b321c0..861b4548 100644 --- a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/ControllersExtensions.cs +++ b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/ControllersExtensions.cs @@ -3,15 +3,9 @@ using Microsoft.Extensions.DependencyInjection; using System; - using System.ComponentModel.DataAnnotations; using System.Linq; - using System.Linq.Expressions; - using System.Reflection; using System.Security.Claims; using System.Security.Principal; - using System.Web.Http; - using System.Web.Http.Controllers; - using System.Web.Http.Dispatcher; using System.Web.Mvc; /// @@ -54,35 +48,11 @@ return services; } - /// - /// Adds controllers of type loaded by reflection from the current assembly to the . - /// On this way all required services are loaded into the controller constructors. - /// - /// provided from the extension method. - /// The same with added services. - public static IServiceCollection AddAPIControllers(this IServiceCollection services) - { - var controllers = typeof(ControllersExtensions) - .Assembly - .GetTypes() - .Where(x => !x.IsAbstract - && typeof(IHttpController).IsAssignableFrom(x)); - - foreach (var controller in controllers) - { - services.AddTransient(controller); - } - - return services; - } - public static IServiceProvider BuildControllerFactory(this IServiceProvider serviceProvider) { var controllerFactory = new ControllerFactory(serviceProvider); ControllerBuilder.Current.SetControllerFactory(controllerFactory); - GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerActivator), new APIControllerActivator(serviceProvider)); - GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerSelector), new APIControllerFactory()); return serviceProvider; } @@ -98,25 +68,5 @@ return ""; } - - public static string Display(this T model, Expression> expression) - { - if (expression.Body is MemberExpression memberExpression) - { - return memberExpression - .Member - .GetCustomAttribute() - .GetName(); - } - else if (expression.Body is UnaryExpression unaryExpression && unaryExpression.Operand is MemberExpression operandExpression) - { - return operandExpression - .Member - .GetCustomAttribute() - .GetName(); - } - - return default(string); - } } } \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/ServiceProviderExtensions.cs b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/ServiceProviderExtensions.cs index fc6000a9..e1498bc2 100644 --- a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/ServiceProviderExtensions.cs +++ b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/ServiceProviderExtensions.cs @@ -1,6 +1,5 @@ namespace LaaProductionWeb.App_Infrastructure { - using System; public static class ServiceProviderExtensions diff --git a/LaaProductionWeb/LaaProductionWeb/App_Start/RouteConfig.cs b/LaaProductionWeb/LaaProductionWeb/App_Start/RouteConfig.cs index d50aa845..1b72b206 100644 --- a/LaaProductionWeb/LaaProductionWeb/App_Start/RouteConfig.cs +++ b/LaaProductionWeb/LaaProductionWeb/App_Start/RouteConfig.cs @@ -18,11 +18,6 @@ routes.MapMvcAttributeRoutes(); - //routes.MapRoute( - // name: "Production", - // url: "Production/{controller}/{action}/{id}", - // defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }); - routes.MapRoute( name: "MVC_Default", url: "{controller}/{action}/{id}", diff --git a/LaaProductionWeb/LaaProductionWeb/App_Start/ServicesConfig.cs b/LaaProductionWeb/LaaProductionWeb/App_Start/ServicesConfig.cs index 75676fa1..5f6b6e54 100644 --- a/LaaProductionWeb/LaaProductionWeb/App_Start/ServicesConfig.cs +++ b/LaaProductionWeb/LaaProductionWeb/App_Start/ServicesConfig.cs @@ -30,7 +30,6 @@ { services .AddControllers() - .AddAPIControllers() .AddTransientServices() .AddDbContext(ApplicationSettings.ConnectionString); diff --git a/LaaProductionWeb/LaaProductionWeb/App_Start/WebApiConfig.cs b/LaaProductionWeb/LaaProductionWeb/App_Start/WebApiConfig.cs index c8f6b18b..b0a9546c 100644 --- a/LaaProductionWeb/LaaProductionWeb/App_Start/WebApiConfig.cs +++ b/LaaProductionWeb/LaaProductionWeb/App_Start/WebApiConfig.cs @@ -15,10 +15,8 @@ { config.MapHttpAttributeRoutes(); - config.Routes.MapHttpRoute( - name: "DefaultApi", - routeTemplate: "api/{controller}/{id}", - defaults: new { id = RouteParameter.Optional }); + config.Routes.MapHttpRoute(name: "AreaApi", routeTemplate: "{area}/{controller}/{action}"); + config.Routes.MapHttpRoute(name: "DefaultApi", routeTemplate: "{controller}"); } } } diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Search/Controllers/WildcardController.cs b/LaaProductionWeb/LaaProductionWeb/Areas/Search/Controllers/WildcardController.cs new file mode 100644 index 00000000..0a590e7b --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Search/Controllers/WildcardController.cs @@ -0,0 +1,11 @@ +namespace LaaProductionWeb.Areas.Search +{ + using System.Web.Http; + + public class WildcardController : SearchAPIController + { + [HttpGet] + public IHttpActionResult Get(string token) + => this.Json($"Found: {token}"); + } +} diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Search/SearchAPIController.cs b/LaaProductionWeb/LaaProductionWeb/Areas/Search/SearchAPIController.cs new file mode 100644 index 00000000..626f8204 --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Search/SearchAPIController.cs @@ -0,0 +1,10 @@ +namespace LaaProductionWeb.Areas.Search +{ + using System.Web.Http; + using System.Web.Mvc; + + [RouteArea("Search")] + public class SearchAPIController : ApiController + { + } +} diff --git a/LaaProductionWeb/LaaProductionWeb/Areas/Search/SearchAreaRegistration.cs b/LaaProductionWeb/LaaProductionWeb/Areas/Search/SearchAreaRegistration.cs new file mode 100644 index 00000000..b75b14fa --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb/Areas/Search/SearchAreaRegistration.cs @@ -0,0 +1,12 @@ +namespace LaaProductionWeb.Areas.Search +{ + using System.Web.Mvc; + + public class SearchAreaRegistration : AreaRegistration + { + public override string AreaName => "Search"; + + public override void RegisterArea(AreaRegistrationContext context) + => context.MapRoute("Search_Default", "Search/{controller}/{action}"); + } +} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/LaaProductionWeb.csproj b/LaaProductionWeb/LaaProductionWeb/LaaProductionWeb.csproj index f1e24602..196c92f0 100644 --- a/LaaProductionWeb/LaaProductionWeb/LaaProductionWeb.csproj +++ b/LaaProductionWeb/LaaProductionWeb/LaaProductionWeb.csproj @@ -150,7 +150,6 @@ - @@ -167,6 +166,9 @@ + + +