Skip to content

Instantly share code, notes, and snippets.

View lucamilan's full-sized avatar
:bowtie:
I may be slow to respond.

Luca Milan lucamilan

:bowtie:
I may be slow to respond.
View GitHub Profile
@lucamilan
lucamilan / gist:1195328
Created September 5, 2011 15:58
Empty VS2010 Solution
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@lucamilan
lucamilan / domain_model_with_business_entity
Created January 3, 2012 15:46
DOMAIN MODEL with BUSINESS EVENTS (original idea Daniel Cazzulino)
/// <summary>
/// Domain Event
/// </summary>
public class CustomerChangeLevel : EventArgs {
public decimal Amount { get; set; }
}
/// <summary>
/// Simple Enum
/// </summary>
@lucamilan
lucamilan / ServiceResolverAdapter.cs
Created March 20, 2012 22:45 — forked from haacked/ServiceResolverAdapter.cs
ServiceResolverAdapter: Allows you to use the ASP.NET MVC DependencyResolver for ASP.NET Web API
public class ServiceResolverAdapter : IDependencyResolver
{
private readonly System.Web.Mvc.IDependencyResolver dependencyResolver;
public ServiceResolverAdapter(System.Web.Mvc.IDependencyResolver dependencyResolver)
{
if (dependencyResolver == null) throw new ArgumentNullException("dependencyResolver");
this.dependencyResolver = dependencyResolver;
}
@lucamilan
lucamilan / program.cs
Created March 21, 2012 12:39 — forked from phillip-haydon/program.cs
RavenDB Projection Sample
using System;
using System.Collections.Generic;
using System.Linq;
using Raven.Abstractions.Indexing;
using Raven.Client;
using Raven.Client.Document;
using Raven.Client.Indexes;
using Raven.Client.Linq;
namespace RavenDBProjectionTest
@lucamilan
lucamilan / gist:2304623
Created April 4, 2012 18:41 — forked from Buthrakaur/gist:1613003
NHibernate QueryOver.List extension to support casting to anonymous types
public static IList<TRes> ListAs<TRes>(this IQueryOver qry, TRes resultByExample)
{
var ctor = typeof (TRes).GetConstructors().First();
return qry.UnderlyingCriteria
.SetResultTransformer(Transformers.AliasToBeanConstructor(ctor))
.List<TRes>();
}
[Fact]
public void ListAs_Should_CastQueryOverResultToTypeSameAsSupliedExampleInstance()
@lucamilan
lucamilan / l2s_repository.cs
Created April 4, 2012 18:45 — forked from derans/l2s_repository.cs
L2S Repository
public class LinqToSqlRepository<TContext>
: IDisposable where TContext : DataContext, new()
{
private readonly DataContext _dc;
public LinqToSqlRepository()
{
_dc = new TContext();
}
@lucamilan
lucamilan / SequentialNumberGenerator.cs
Created April 27, 2012 12:55 — forked from nberardi/SequentialNumberGenerator.cs
Sequential Number Generator for RavenDB
private static readonly object GeneratorLock = new object();
///<summary>
/// Create the next id (numeric)
///</summary>
private int NextAccountNumber()
{
lock (GeneratorLock)
{
using (new TransactionScope(TransactionScopeOption.Suppress))
@lucamilan
lucamilan / IObjectContext.cs
Created April 27, 2012 12:56 — forked from nberardi/IObjectContext.cs
Code for my post on Repository Pattern for Entity Framework: http://coderjournal.com/2010/11/entity-framework-repository-pattern/
public interface IObjectContext : IDisposable
{
ObjectContextOptions ContextOptions { get; }
TEntity CreateObject<TEntity>() where TEntity : class;
IObjectSet<TEntity> CreateObjectSet<TEntity>() where TEntity : class;
int SaveChanges();
}
@lucamilan
lucamilan / IDatabaseInitializer
Created May 11, 2012 10:12
Custom Scenario for better EF CodeFirst Integration Tests
using System;
using System.Data.Common;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Objects;
using NUnit.Framework;
namespace MyPrj.Infrastructure.IntegrationTests
{
/// <summary>
@lucamilan
lucamilan / gist:2700630
Created May 15, 2012 10:22
Javascript Logging (Server & Client)
// client side logging
window.console = window.console || function () { var a = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"]; window.console = {}; for (var b = 0; b < a.length; ++b) window.console[a[b]] = function () { } } ();
// server side logging
window.onerror = function (msg, url, line) {
if (encodeURIComponent && window.XMLHttpRequest && window.navigator) {
try {
var req = new XMLHttpRequest();
var params = "agent=" + navigator.userAgent + "&line=" + line + "&msg=" + msg + "&url=" + encodeURIComponent(url);
req.open("POST", "/LogJs.aspx", true);