Skip to content

Commit

Permalink
Update RegistrationExtensions.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
ffMathy committed Apr 5, 2019
1 parent f592452 commit ae69ce5
Showing 1 changed file with 20 additions and 16 deletions.
Expand Up @@ -19,26 +19,30 @@ public static class RegistrationExtensions
.Where(x => DoesTypeMatchFilters(settings, x));
foreach (var classType in classTypes)
{
var implementedInterfaceTypes = classType
.GetInterfaces()
.Where(x => DoesTypeMatchFilters(settings, x)); ;
foreach (var implementedInterfaceType in implementedInterfaceTypes)
{
var implementationType = classType;
var interfaceType = implementedInterfaceType;
try {
var implementedInterfaceTypes = classType
.GetInterfaces()
.Where(x => DoesTypeMatchFilters(settings, x)); ;
foreach (var implementedInterfaceType in implementedInterfaceTypes)
{
var implementationType = classType;
var interfaceType = implementedInterfaceType;

if (!interfaceType.IsGenericType && classType.IsGenericType)
continue;
if (!interfaceType.IsGenericType && classType.IsGenericType)
continue;

if (implementationType.IsGenericType)
implementationType = implementationType.GetGenericTypeDefinition();
if (implementationType.IsGenericType)
implementationType = implementationType.GetGenericTypeDefinition();

if (implementationType.IsGenericType && interfaceType.IsGenericType)
interfaceType = interfaceType.GetGenericTypeDefinition();
if (implementationType.IsGenericType && interfaceType.IsGenericType)
interfaceType = interfaceType.GetGenericTypeDefinition();

serviceCollection.AddScoped(
interfaceType,
implementationType);
serviceCollection.AddScoped(
interfaceType,
implementationType);
}
} catch(Exception ex) {
throw new Exception("Could not load type " + classType.FullName, ex);
}
}
}
Expand Down

0 comments on commit ae69ce5

Please sign in to comment.