Skip to content

Instantly share code, notes, and snippets.


Sean G. Wright seangwright

Block or report user

Report or block seangwright

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View PageTypeRouteAttributeCacheHelperCacheHelper.cs
public static class PageTypeRouteAttributeCacheHelper
public static readonly Dictionary<string, ControllerActionPair> ClassNameLookup;
static PageTypeRouteAttributeCacheHelper()
var controllerTypes = typeof(PageTypeRouteAttributeCacheHelper)
.Where(t =>
seangwright / JsonDotNetValueProviderFactory.cs
Created Jun 26, 2019
Custom Json Serialization for ASP.NET MVC
View JsonDotNetValueProviderFactory.cs
/// <summary>
/// From
/// </summary>
public class JsonDotNetValueProviderFactory : ValueProviderFactory
private readonly JsonSerializerSettings serializerSettings;
public JsonDotNetValueProviderFactory(JsonSerializerSettings serializerSettings)
Guard.Against.Null(serializerSettings, nameof(serializerSettings));
seangwright / ApiExceptionResult.cs
Last active Jun 26, 2019
Error Handling in Web Api 2
View ApiExceptionResult.cs
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)
seangwright / KenticoMvcApp.csproj
Last active Jun 26, 2019
WebApi2 Swashbuckle integration
View KenticoMvcApp.csproj
<!-- Add this to ensure the XML comments are picked up by the Swashbuckle integration -->
View UserInfoTests.cs
public class UserInfoTests : UnitTests
public void IsAuthorized_Will_Return_True_When_User_Is_In_All_Roles(
int userId,
string userName,
int siteId,
string siteName,
int roleId1,
seangwright / DependencyResolverConfig.cs
Last active Jul 10, 2019
Kentico 12: Design Patterns Part 4 - Adding Dependency Injection to the CMS
View DependencyResolverConfig.cs
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
View Kentico12-TipsTricks-Structure-ProductsController.cs
public class ProductsController : Controller
private readonly IProductsQuery productsQuery;
private readonly IProductDetailQuery productDetailQuery;
public ProductsController(
IProductsQuery productsQuery,
IProductDetailQuery productDetailQuery)
// ...
View Kentico12-TipsTricks-Structure-RouteConfig.cs
/// DependencyConfiguration.cs
/// --------------------------
// ContainerBuilder builder from Autofac
.Where(t => t.IsClass && !t.IsAbstract && t.Name.EndsWith("RouteRegistry"))
/// RouteConfig.cs
/// --------------
View Kentico12-TipsTricks-Structure-RouteCollectionExtensions.cs
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);
View Kentico12-TipsTricks-Structure-HomeRouteRegistry.cs
public class HomeRouteRegistry : IRouteRegistry
public int Priority => RoutePriorityReference.LOWEST;
public void RegisterRoutes(RouteCollection routes) =>
name: "Home",
url: "",
nameOfDefaultAction: c => nameof(c.Index)
You can’t perform that action at this time.