Created
March 5, 2010 14:52
-
-
Save timwingfield/322769 to your computer and use it in GitHub Desktop.
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
public class RepositoryConventionScanner : IRegistrationConvention | |
{ | |
public void Process(Type type, Registry registry) | |
{ | |
Type repoForType = GetGenericParamFor(type.BaseType, typeof(Repository<>)); | |
if (repoForType != null) | |
{ | |
var genType = typeof(IRepository<>).MakeGenericType(repoForType); | |
registry.For(genType).Add(typeof (Repository<>)); | |
} | |
} | |
private static Type GetGenericParamFor(Type typeToInspect, Type genericType) | |
{ | |
if(typeToInspect != null && typeToInspect.IsGenericType && typeToInspect.GetGenericTypeDefinition().Equals(genericType)) | |
{ | |
return typeToInspect.GetGenericArguments()[0]; | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment