This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ApiExceptionResult : IHttpActionResult | |
{ | |
private static readonly MediaTypeHeaderValue mediaType = new MediaTypeHeaderValue("application/json"); | |
private readonly ApiError errorResponse; | |
private readonly JsonMediaTypeFormatter jsonMediaTypeFormatter; | |
private readonly HttpRequestMessage requestMessage; | |
private readonly HttpStatusCode statusCode; | |
public ApiExceptionResult(HttpRequestMessage requestMessage, HttpStatusCode statusCode, ApiError errorResponse, JsonMediaTypeFormatter jsonMediaTypeFormatter) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Add this to ensure the XML comments are picked up by the Swashbuckle integration --> | |
<PropertyGroup> | |
<DocumentationFile>bin\KenticoMvcApp.xml</DocumentationFile> | |
</PropertyGroup> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TextFixture] | |
public class UserInfoTests : UnitTests | |
{ | |
[Test] | |
public void IsAuthorized_Will_Return_True_When_User_Is_In_All_Roles( | |
int userId, | |
string userName, | |
int siteId, | |
string siteName, | |
int roleId1, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class DependencyResolverConfig | |
{ | |
public static IContainer BuildContainer() | |
{ | |
var builder = new ContainerBuilder(); | |
// My registration classes use a "fluent" interface, always returning the ContainerBuilder | |
// so the next call can be chained off the previous | |
var container = builder | |
.RegisterApplicationTypes() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ProductsController : Controller | |
{ | |
private readonly IProductsQuery productsQuery; | |
private readonly IProductDetailQuery productDetailQuery; | |
public ProductsController( | |
IProductsQuery productsQuery, | |
IProductDetailQuery productDetailQuery) | |
{ | |
// ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// DependencyConfiguration.cs | |
/// -------------------------- | |
// ContainerBuilder builder from Autofac | |
builder.RegisterAssemblyTypes(assemblies) | |
.Where(t => t.IsClass && !t.IsAbstract && t.Name.EndsWith("RouteRegistry")) | |
.AsImplementedInterfaces(); | |
/// RouteConfig.cs | |
/// -------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class RouteCollectionExtensions | |
{ | |
public static void MapRoute<T>( | |
this RouteCollection routes, | |
string name, | |
string url, | |
Func<T, string> nameOfDefaultAction) where T : Controller | |
{ | |
string controller = typeof(T).RemoveControllerSuffix(); | |
string action = nameOfDefaultAction(default); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HomeRouteRegistry : IRouteRegistry | |
{ | |
public int Priority => RoutePriorityReference.LOWEST; | |
public void RegisterRoutes(RouteCollection routes) => | |
routes.MapRoute<HomeController>( | |
name: "Home", | |
url: "", | |
nameOfDefaultAction: c => nameof(c.Index) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Sourced from https://benfoster.io/blog/improving-aspnet-mvc-routing-configuration | |
/// </summary> | |
public interface IRouteRegistry | |
{ | |
/// <summary> | |
/// Provides the global <see cref="RouteCollection"/> to which the Registery's routes | |
/// should be added | |
/// </summary> | |
/// <param name="routes"></param> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RouteConfig | |
{ | |
public static void RegisterRoutes(RouteCollection routes) | |
{ | |
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); | |
routes.MapRoute( | |
name: "Default", | |
url: "{controller}/{action}/{id}", | |
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } |