Skip to content

Instantly share code, notes, and snippets.

View RemiBou's full-sized avatar

Rémi BOURGAREL RemiBou

View GitHub Profile
@RemiBou
RemiBou / gist:3690177
Created September 10, 2012 10:27
Instantiating TransactionScope With Ninject
/// <summary>
/// Load your modules or register your services here!
/// </summary>
/// <param name="kernel">The kernel.</param>
private static void RegisterServices(IKernel kernel)
{
kernel.Bind<MyDBContext>()
.To<MyDBContext>()
.InRequestScope()
@RemiBou
RemiBou / gist:3690611
Created September 10, 2012 12:17
RemiDDD sample Command
public class SellProductCommand : ICommand
{
public int ProductId { get; set; }
public int CustomerId { get; set; }
public string SellerComment { get; set; }
}
@RemiBou
RemiBou / gist:3690641
Created September 10, 2012 12:26
RemiDDD : Command Handler Sample
public class SelectProductCommandHandler : ICommandHandler<SellProductCommand>
{
private readonly DbContext _dbcontext;
public SelectProductCommandHandler(DbContext dbcontext)
{
_dbcontext = dbcontext;
}
public void Execute(SellProductCommand command)
@RemiBou
RemiBou / gist:3690647
Created September 10, 2012 12:27
Remi DDD : sample entities
public class Product
{
public string Name { get; set; }
public int Id { get; set; }
public decimal Price { get; set; }
}
public class Order
{
public int Id { get; set; }
public class Program
{
public static void Main(params object[] para)
{
//ninject bootstrapping
var standardKernel = new StandardKernel();
standardKernel.Bind<DbContext>().To<DbContext>();
standardKernel.Bind<MessageProcessor>().To<MessageProcessor>();
MessageProcessor messageProcessor = standardKernel.Get<MessageProcessor>();
//link the commands with their handlers, and the events with their observers
@RemiBou
RemiBou / gist:3705756
Created September 12, 2012 10:17
Unit Test and Entity Framework 4 Controller
public class CustomerController : Controller
{
private MyDbContext _dbContext;
public ActionResult Index()
{
return View(_dbContext.Customers.OrderBy(c => c.Name).ToList());
}
}
public class MyDbContext : DbContext
{
public class CustomerController : Controller
{
private IMyDbContext _dbContext;
public CustomerController(IMyDbContext dbContext)
{
_dbContext = dbContext;
}
public ActionResult Index()
public class FakeMyDbContext : IMyDbContext
{
public FakeMyDbContext(IEnumerable<Customer> customers )
{
Customers = customers.AsQueryable();
}
public IQueryable<Customer> Customers { get; set; }
}
public class Record
{
public DateTime Start;
public DateTime End;
public long Id;
public TimeSpan Duration => End - Start;
private static long[] _pows = Enumerable.Range(0, 8).Select(i => (long)Math.Pow(10, i)).ToArray();
public Record(string line)
{
/**
* The security configuration.
* <P>
* @author Pangee.
* @version 1.0.0-SNAPSHOT
*/
@Configuration
@EnableWebSecurity
@EnableRedisHttpSession
@EnableGlobalMethodSecurity(prePostEnabled = true)