Skip to content

Commit

Permalink
Merge pull request #6 from westermo/feature/DefaultSelf
Browse files Browse the repository at this point in the history
Assume [Self] when no interface is present, and allow interface injections to be composite
  • Loading branch information
carl-andersson-at-westermo authored Apr 3, 2024
2 parents 9e21234 + 7d919fe commit ce72e10
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions FactoryGenerator/Injection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ private Injection(INamedTypeSymbol type, ImmutableArray<INamedTypeSymbol> interf

var singleInstance = false;
var acquireChildInterfaces = false;
var asSelf = false;
if(namedTypeSymbol.Interfaces.Length == 0)
{
asSelf = true;
}
if (namedTypeSymbol.TypeKind == TypeKind.Interface)
{
asSelf = true;
}
BooleanInjection? boolean = null;
HashSet<INamedTypeSymbol> attributedInterfaces = new(SymbolEqualityComparer.Default);
HashSet<INamedTypeSymbol> preventedInterfaces = new(SymbolEqualityComparer.Default);
Expand Down Expand Up @@ -207,7 +216,7 @@ private Injection(INamedTypeSymbol type, ImmutableArray<INamedTypeSymbol> interf

break;
case "SelfAttribute":
attributedInterfaces.Add(namedTypeSymbol);
asSelf = true;
break;
case "BooleanAttribute":
boolean = HandleBoolean(attributeData);
Expand All @@ -218,9 +227,9 @@ private Injection(INamedTypeSymbol type, ImmutableArray<INamedTypeSymbol> interf
}

var interfaces = acquireChildInterfaces ? namedTypeSymbol.AllInterfaces : namedTypeSymbol.Interfaces;
if (namedTypeSymbol.TypeKind == TypeKind.Interface)
if (asSelf)
{
interfaces = ImmutableArray.Create(namedTypeSymbol);
interfaces = interfaces.Add(namedTypeSymbol);
}

interfaces = interfaces.AddRange(attributedInterfaces);
Expand Down

0 comments on commit ce72e10

Please sign in to comment.