Skip to content

Instantly share code, notes, and snippets.

View aikmeng's full-sized avatar

Ang Aik Meng aikmeng

View GitHub Profile
@aikmeng
aikmeng / DisableLazyLoadingInEF
Created May 8, 2014 16:38
How to disable lazy loading in entity framework
public class CustomDBContext : DbContext
{
public CustomDBContext()
{
this.Configuration.LazyLoadingEnabled = false;
}
}
@aikmeng
aikmeng / Log.cs
Created April 16, 2014 15:29
Ninject and ASP.NET Filter Injection
namespace ExperimentWebApiNinject.Utilities.Interface
{
public interface ILog
{
void Write(string message);
}
public class Log : ILog
{
public void Write(string message)
@aikmeng
aikmeng / gist:6748867
Created September 29, 2013 02:40
Allow unit test by mocking up dbcontext and dbset.
namespace ExperimentMoq
{
public class DbEntity
{
public int Id { get; set; }
public string Name { get; set; }
}
public class CustomDbContext : DbContext, IDisposable
{
@aikmeng
aikmeng / webapi_return_json
Created September 27, 2013 23:17
MVC Web API to return JSON values by default. This will still support xml request.
var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml");
config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType);
@aikmeng
aikmeng / ExperimentNinjectEF.Data
Created September 25, 2013 15:13
Create wrapper for DBContext
namespace ExperimentNinjectEF.Data.Interface
{
public interface IDbContext : IDisposable
{
DbSet<TEntity> Set<TEntity>() where TEntity : class;
int SaveChanges();
}
}
@aikmeng
aikmeng / ExperimentNinjectComposition.Console
Last active December 23, 2015 21:59
Compose modules using Ninject
namespace ExperimentNinjectComposition
{
class Program
{
static void Main(string[] args)
{
IKernel kernel = new StandardKernel(
new ExperimentNinjectComposition.Core.Module(),
new ExperimentNinjectComposition.ModuleA.Module(),
new ExperimentNinjectComposition.ModuleB.Module());