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 / 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 / IncludeInterfacesModelMetadataProvider.cs
Created June 10, 2012 10:07 — forked from kenegozi/IncludeInterfacesModelMetadataProvider.cs
Allowing MVC3 model validator to use interface attributes
class IncludeInterfacesModelMetadataProvider : DataAnnotationsModelMetadataProvider {
protected override IEnumerable<Attribute> FilterAttributes(Type containerType, PropertyDescriptor propertyDescriptor, IEnumerable<Attribute> attributes) {
var validationAttributesOnInterfaces =
from i in containerType.GetInterfaces()
from p in i.GetProperties()
where p.Name == propertyDescriptor.Name
from a in p.GetCustomAttributes(true).Cast<Attribute>()
where typeof(ValidationAttribute).IsAssignableFrom(a.GetType())
select a;
@lucamilan
lucamilan / gist:2905214
Created June 10, 2012 12:11 — forked from millermedeiros/gist:1189235
Explain difference between revealing module pattern and using a constructor as namespace
//create our "FOO" namespace
window.FOO = window.FOO || {};
FOO.app1 = {
bar : 'foo',
init : function(){
//this wont work as expected since timeout changes scope
@lucamilan
lucamilan / gist:3238005
Created August 2, 2012 15:37 — forked from aliostad/gist:3202814
Serialisation and deserialisation of HTTP request and response messages in ASP.NET Web API
public interface IHttpMessageSerializer
{
void Serialize(HttpResponseMessage response, Stream stream);
void Serialize(HttpRequestMessage request, Stream stream);
HttpResponseMessage DeserializeToResponse(Stream stream);
HttpRequestMessage DeserializeToRequest(Stream stream);
}
public class MessageContentHttpMessageSerializer : IHttpMessageSerializer
@lucamilan
lucamilan / jQuery.ajaxQueue.min.js
Created August 9, 2012 12:49 — forked from gnarf/jQuery.ajaxQueue.min.js
jQuery.ajaxQueue - A queue for ajax requests
/*
* jQuery.ajaxQueue - A queue for ajax requests
*
* (c) 2011 Corey Frang
* Dual licensed under the MIT and GPL licenses.
*
* Requires jQuery 1.5+
*/
(function(a){var b=a({});a.ajaxQueue=function(c){function g(b){d=a.ajax(c).then(b,b).done(e.resolve).fail(e.reject)}var d,e=a.Deferred(),f=e.promise();b.queue(g),f.abort=function(h){if(d)return d.abort(h);var i=b.queue(),j=a.inArray(g,i);j>-1&&i.splice(j,1),e.rejectWith(c.context||c,[f,h,""]);return f};return f}})(jQuery)