Created
February 1, 2020 07:35
-
-
Save PradeepLoganathan/152bd70dbda88390f8a347d285380124 to your computer and use it in GitHub Desktop.
Dynamic registration of types using assembly scanning.
This file contains 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
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