-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Description
Looking at https://github.com/dodyg/practical-aspnetcore/blob/net6.0/projects/dependency-injection/dependency-injection-3/Program.cs - as far as I know this code
var types = System.AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(x => x.GetTypes())
.Where(p => type.IsAssignableFrom(p) && p.IsClass);
will find only types in assemblies loaded to this moment. For perf reason, .NET loads assemblies only when needed, so GetAssemblies()
is often only a subset of all the app dependencies/assemblies.
A couple of options (not sure if there are more or if there's a way to force all assemblies to be discoverable):
- introducing static references to all assemblies, so they are loaded when the app starts
- scanning the folder and manually load each assembly before calculating
types
(caching the result if possible, so this is done only once or on demand)
Metadata
Metadata
Assignees
Labels
No labels