Created
April 24, 2014 18:20
-
-
Save kshyju/11264331 to your computer and use it in GitHub Desktop.
Unity with generics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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