Skip to content

Instantly share code, notes, and snippets.

@johnw86
Created March 22, 2018 12:08
Show Gist options
  • Save johnw86/8e02b855c5d31069835c052ab56367fc to your computer and use it in GitHub Desktop.
Save johnw86/8e02b855c5d31069835c052ab56367fc to your computer and use it in GitHub Desktop.
Use Reflection to create instance of all implementations of an interface.
var implementations = Assembly.GetExecutingAssembly().GetTypes()
.Where(x => typeof(IInterface).IsAssignableFrom(x) &&
!x.IsInterface &&
!x.IsAbstract &&
x.IsClass &&
x.IsPublic)
.Select(x => Activator.CreateInstance(x) as IInterface);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment