Skip to content

Instantly share code, notes, and snippets.

View ielcoro's full-sized avatar

Iñaki Elcoro ielcoro

  • Asemblia
  • Bilbao
View GitHub Profile
@ielcoro
ielcoro / AutoRegistration.cs
Created May 28, 2013 07:27
Unity 3 Mapping Examples
public static void Configure(UnityContainer container)
{
//Mix explicit mapping with Auto-Registration
container.RegisterType<IEntityFrameworkUnitOfWork, UnitOfWork>(new HierarchicalLifetimeManager(), new InjectionConstructor());
//Select only repositories in loaded assemblies
container.RegisterTypes(AllClasses.FromLoadedAssemblies()
.Where(type => type.BaseType != null && type.BaseType.IsGenericType &&
type.BaseType.GetGenericTypeDefinition() == typeof(BaseRepository<>)),
WithMappings.FromMatchingInterface,
@ielcoro
ielcoro / ConfigurationStore.cs
Created May 31, 2013 10:18
Dynamic Configuration Example
class ConfigurationStore : DynamicObject
{
public static TModel GetStore<TModel>()
{
return (dynamic)new ConfigurationStore();
}
private object GetConfigurationValue(string name)
{
object value = null;
@ielcoro
ielcoro / WithoutIf.cs
Created June 15, 2013 11:41
CodeBreaker Kata without ifs
class Rules
{
private string passcode;
public Rules(string passcode)
{
this.passcode = passcode;
}
internal string Match(string code)
@ielcoro
ielcoro / Expressions.cs
Created November 6, 2013 07:59
Guard exception helper
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace Ormazabal.PanelMonitoring.Helpers
{
static class Expressions
@ielcoro
ielcoro / Add-Account.ps1
Created December 8, 2013 14:53
Azure Web Sites IDN Domain registration steps
Add-Account
Select-Subscription -SubscriptionName mysubscription
@ielcoro
ielcoro / WebApiFilterProvider.cs
Created December 31, 2013 14:55
Asp.Net Filtering Inyection
public class WebApiUnityFilterProvider : ActionDescriptorFilterProvider, IFilterProvider
{
private readonly IUnityContainer container;
public WebApiUnityFilterProvider(IUnityContainer container)
{
this.container = container;
}
public new IEnumerable<FilterInfo> GetFilters(HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)
@ielcoro
ielcoro / PerLifeTimeRegister.cs
Created January 4, 2014 17:36
MVC and Web Api Unity Integration
public static void RegisterTypes(IUnityContainer container)
{
// NOTE: To load from web.config uncomment the line below. Make sure to add a Microsoft.Practices.Unity.Configuration to the using statements.
// container.LoadConfiguration();
container.RegisterType<IUnitOfWork, UnitOfWork>(new PerRequestLifetimeManager());
}
@ielcoro
ielcoro / TypeActivator.cs
Created January 6, 2014 11:42
Type Activator with Lambdas
internalstaticclass TypeActivator
{
public static Func<TBase> Create<TBase>(Type instanceType)
where TBase : class
{
Contract.Assert(instanceType != null);
NewExpression newInstanceExpression = Expression.New(instanceType);
return Expression.Lambda<Func<TBase>>(newInstanceExpression).Compile();
}
@ielcoro
ielcoro / sharepointmenu.js
Last active August 29, 2015 14:08
Sharepoint Menu
var menu = CMenu("miNuevoMenu");
//Añadir opción
// CAMOpt(menu, opt.DisplayText, opt.OnClickAction, opt.ImageUrl, opt.ImageAltText, String(100 * idx), opt.Description);
var irAExpedientes = "STSNavigate2(event,'/SitePages/Expedientes.aspx')";
var imagen = "/_layouts/15/images/MiIcono.png";
var indice = 100;
var opcion1 = CAMOpt(menu, "Opción 1", irAExpedientes , imagen, "Texto Alternativo", indice, "Yo soy la opción1");
//Opcional: controlar el id
@ielcoro
ielcoro / DeleteField.ps1
Created December 11, 2014 11:10
Sharepoint Powershell Snippets
$fieldName = "field"
$contentTypeId = New-Object Microsoft.Sharepoint.SPContentTypeId("0x010100629D00608F814DD6AC8A86903AEE72AA")
Add-PSSnapin Microsoft.Sharepoint.Powershell
$web = Get-SPWeb http://cun04
$contentType = $web.ContentTypes | ? { $_.ID.IsParentOf($contentTypeId) }
$contentType.FieldLinks.Delete($fieldName)
$contentType.Update($true)