Skip to content

Instantly share code, notes, and snippets.

@PradeepLoganathan
Created February 1, 2020 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PradeepLoganathan/152bd70dbda88390f8a347d285380124 to your computer and use it in GitHub Desktop.
Save PradeepLoganathan/152bd70dbda88390f8a347d285380124 to your computer and use it in GitHub Desktop.
Dynamic registration of types using assembly scanning.
Assembly ConsoleAppAssembly = typeof(Program).Assembly;
var ConsoleAppTypes =
from type in ConsoleAppAssembly.GetTypes()
where !type.IsAbstract
where typeof(ICustomer).IsAssignableFrom(type)
select type;
foreach (var type in ConsoleAppTypes)
{
services.AddTransient(typeof(ICustomer), type);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment