Skip to content

Instantly share code, notes, and snippets.

@codehaks
codehaks / LiteDbServiceExtention.cs
Created October 1, 2018 16:48
LiteDb Service for ASP.NET Core
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
namespace BugPages.Common
{
public static class LiteDbServiceExtention
{
public static void AddLiteDb(this IServiceCollection services,string databasePath)
{
services.AddTransient<LiteDbContext, LiteDbContext>();
@codehaks
codehaks / NotFoundAttribute.cs
Created December 27, 2017 09:35
ASP MVC ActionFilter to simulate NotFound result
using System.Web;
using System.Web.Mvc;
namespace MyWebProject.Common
{
public class NotFoundAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
throw new HttpException(404, "Requested page not found");
@codehaks
codehaks / startup.cs
Created September 25, 2017 06:47
Alternate pipeline for Error Handling
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
@codehaks
codehaks / startup.cs
Created September 15, 2017 09:22
Simulating Error handling in ASP.NET Core
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
namespace ErrorDemo {
@codehaks
codehaks / startup.cs
Last active September 6, 2017 20:10
Simulating app.Run with app.Use in ASP.NET Core 2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
namespace MiddlewareDemo