Skip to content

Instantly share code, notes, and snippets.

🐻
Learning...

Sean G. Wright seangwright

🐻
Learning...
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)
.Assembly
.GetTypes()
.Where(t =>
@seangwright
seangwright / JsonDotNetValueProviderFactory.cs
Created Jun 26, 2019
Custom Json Serialization for ASP.NET MVC
View JsonDotNetValueProviderFactory.cs
/// <summary>
/// From https://github.com/garysharp/Disco/commit/1dfa3f4f15fe4fc093e90e4cd490dd06cc30cf07
/// </summary>
public class JsonDotNetValueProviderFactory : ValueProviderFactory
{
private readonly JsonSerializerSettings serializerSettings;
public JsonDotNetValueProviderFactory(JsonSerializerSettings serializerSettings)
{
Guard.Against.Null(serializerSettings, nameof(serializerSettings));
@seangwright
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
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 -->
<PropertyGroup>
<DocumentationFile>bin\KenticoMvcApp.xml</DocumentationFile>
</PropertyGroup>
View UserInfoTests.cs
[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,
@seangwright
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
.RegisterApplicationTypes()
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
builder.RegisterAssemblyTypes(assemblies)
.Where(t => t.IsClass && !t.IsAbstract && t.Name.EndsWith("RouteRegistry"))
.AsImplementedInterfaces();
/// 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) =>
routes.MapRoute<HomeController>(
name: "Home",
url: "",
nameOfDefaultAction: c => nameof(c.Index)
);
You can’t perform that action at this time.