I was digging though an MVC example that I downloaded a few months ago and ran across a foreach
loop that uses the AppDomain.CurrentDomain
. I was hoping someone could explain what the foreach
loop is searching for.
foreach (var assembly in AppDomain.CurrentDomain
.GetAssemblies()
.Where(a => a.GetName().Name.Contains("Spring")))
{
var configTypes = assembly
.GetTypes()
.Where(t => t.BaseType != null
&& t.IsClass
&& !t.IsAbstract
&& t.BaseType.IsGenericType
&& t.BaseType.GetGenericTypeDefinition() == typeof(EntityTypeConfiguration<>)
&& t.BaseType.GetGenericArguments().Any(ta => _modelInterfaceType.IsAssignableFrom(ta)));
foreach (var type in configTypes)
{
var entityType = type.BaseType.GetGenericArguments().Single();
var entityConfig = assembly.CreateInstance(type.FullName);
addMethod.MakeGenericMethod(entityType)
.Invoke(modelBuilder.Configurations, new object[] { entityConfig });
}
}
I do understand that runs the loop one time per assembly that it finds in the AppDomain.CurrentDomain.GetAssemblies
and the .Where()
is just a filter but I am not really sure how that filter is working or the data it is searching for in the AppDomain
.
Note: I have never used the AppDomain
function and really don't understand how it works.