Skip to content

Instantly share code, notes, and snippets.

@kshyju
Created April 24, 2014 18:20
Show Gist options
  • Save kshyju/11264331 to your computer and use it in GitHub Desktop.
Save kshyju/11264331 to your computer and use it in GitHub Desktop.
Unity with generics
using System;
using Microsoft.Practices.Unity;
public class Program
{
public interface ILoader<IPoco>
{
string Name {get;}
}
public class DragonLoader<IPoco> : ILoader<CustomerPoco>
{
public string Name
{
get
{
return "Me, I am Dragon loader";
}
}
}
public interface IPoco
{
}
public class CustomerPoco : IPoco
{
}
public void Main()
{
IUnityContainer container = new UnityContainer();
container.RegisterType(typeof(ILoader<IPoco>), typeof(DragonLoader<CustomerPoco>));
Console.WriteLine("Hoping that now i will get all the registrations");
var loaders = container.ResolveAll<ILoader<IPoco>>();
foreach(var loader in loaders)
{
Console.WriteLine(loader.Name);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment