Skip to content

Instantly share code, notes, and snippets.

View cosoria's full-sized avatar

Carlos Osoria cosoria

  • Oxoria Consulting Inc
  • Winnipeg, CA
View GitHub Profile
@cosoria
cosoria / profile.ps1
Created April 5, 2018 10:24
Powershell Profile
# add prompt
function Global:prompt {"PS [$Env:username]@$PWD`n>"}
# Chocolatey profile
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
Import-Module "$ChocolateyProfile"
}
@cosoria
cosoria / SetupIISForwardSecrecyTls12.ps1
Created January 12, 2018 15:20
Configure IIS with Perfect Forward Secrecy and TLS 1.2
# Copyright 2017, Alexander Hass
# http://www.hass.de/content/setup-your-iis-ssl-perfect-forward-secrecy-and-tls-12
#
# Version 1.8
# - Windows 2016 powershell 5.1.14393.1532 requires 'else' statements in the same line after to the closing 'if' curly quote.
# Version 1.7
# - Windows Version compare failed. Get-CimInstance requires Windows 2012 or later.
# Version 1.6
# - OS version detection for cipher suites order.
# Version 1.5
@cosoria
cosoria / ApplicationDbContext.cs
Created October 11, 2017 15:30
Sample Application DbContext
public class ApplicationDbContext<TContext> : EntityFrameworkContext<TContext> where TContext : DbContext, IEntityFrameworkContext
{
protected ApplicationDbContext() : this(new ConnectionStringProvider().GetDefaultConnectionString())
{
}
protected ApplicationDbContext(string nameOrConnectionString) : base(nameOrConnectionString)
{
}
}
@cosoria
cosoria / NLogDbCommandInterceptor.cs
Created October 11, 2017 15:27
NLog Command Interceptor allows to see queries on the logs
public class NLogDbCommandInterceptor : IDbCommandInterceptor
{
private ILogger _logger;
private readonly Func<NLogDbCommandInterceptor, ILogger> _loggerFactory = interceptor => LoggerFactory.Instance.Create(interceptor);
private ILogger Logger
{
get
{
if (_logger == null)
public interface IEntityFrameworkUnitOfWork : IUnitOfWork
{
IEntityFrameworkContext Context { get; }
}
public interface IEntityFrameworkUnitOfWork<TContext> : IEntityFrameworkUnitOfWork where TContext : class, IEntityFrameworkContext
{
new TContext Context { get; }
}
@cosoria
cosoria / IEntityFrameworkContext.cs
Created October 11, 2017 15:22
IEntityFrameworkContext interface
public interface IEntityFrameworkContext : IDataContext
{
IDbSet<TEntity> GetDbSetOf<TEntity>() where TEntity : class;
void MarkAsAdded(object entity);
void MarkAsModified(object entity);
void MarkAsDeleted(object entity);
void MarkAsUnchanged(object entity);
void ExtendQueryTimeout();
}
@cosoria
cosoria / EntityFrameworkUnitOfWork.cs
Created October 11, 2017 15:20
EntityFramework Unit of Work
public class EntityFrameworkUnitOfWork : IEntityFrameworkUnitOfWork
{
private readonly IEntityFrameworkContext _context;
public EntityFrameworkUnitOfWork(IEntityFrameworkContext context)
{
_context = context;
}
public IEntityFrameworkContext Context
@cosoria
cosoria / EntityFrameworkRepository.cs
Created October 11, 2017 15:17
Base class for Entity Framework Repositories
public abstract class EntityFrameworkRepository<TEntity> : Disposable, IRepository<TEntity> where TEntity : IEntity
{
protected readonly IEntityFrameworkUnitOfWork _uow;
protected readonly IEntityFrameworkContext _context;
protected EntityFrameworkRepository(IEntityFrameworkUnitOfWork uow)
{
_uow = uow;
_context = uow.Context;
}
@cosoria
cosoria / EntityFrameworkContext.cs
Created October 11, 2017 15:14
EntityFrameworkContext is the class that dynamically loads its configuration from the assembly
public class EntityFrameworkContext<TContext> : DbContext, IEntityFrameworkContext where TContext : DbContext
{
public ObjectContext ObjectContext { get { return ((IObjectContextAdapter)this).ObjectContext; } }
protected EntityFrameworkContext() : base()
{
Database.SetInitializer<TContext>(null);
}
protected EntityFrameworkContext(string nameOrConnectionString) : base(nameOrConnectionString)
@cosoria
cosoria / DynamicEntityTypeConfiguration.cs
Created October 11, 2017 15:12
EntityTypeConfiguration configuration base class of which all Configuration inherits from
public class DynamicEntityTypeConfiguration<TConfiguration> : EntityTypeConfiguration<TConfiguration> where TConfiguration : class, new()
{
}