Skip to content

Commit

Permalink
Merge pull request #150 from hadashiA/ku/fix-constructor-stripped-com…
Browse files Browse the repository at this point in the history
…ponent

Allow no constructor (stripped) for Component
  • Loading branch information
hadashiA authored Feb 26, 2021
2 parents 0f7e504 + 6d1c6f4 commit 4325761
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions VContainer/Assets/VContainer/Runtime/Internal/TypeAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,13 @@ public static InjectTypeInfo Analyze(Type type)

if (injectConstructor == null)
{
throw new VContainerException(type, $"Type does not found injectable constructor, type: {type.Name}");
#if UNITY_2018_4_OR_NEWER
// It seems that Unity sometimes strips the constructor of Component at build time.
// In that case, allow null.
if (!type.IsSubclassOf(typeof(UnityEngine.Component)))
#endif
throw new VContainerException(type, $"Type does not found injectable constructor, type: {type.Name}");
}

// Methods, [Inject] Only
var injectMethods = default(List<InjectMethodInfo>);
foreach (var methodInfo in type.GetRuntimeMethods())
Expand Down Expand Up @@ -187,9 +191,12 @@ static void CheckCircularDependencyRecursive(Type type, Stack<Type> stack)
stack.Push(type);
if (Cache.TryGetValue(type, out var injectTypeInfo))
{
foreach (var x in injectTypeInfo.InjectConstructor.ParameterInfos)
if (injectTypeInfo.InjectConstructor != null)
{
CheckCircularDependencyRecursive(x.ParameterType, stack);
foreach (var x in injectTypeInfo.InjectConstructor.ParameterInfos)
{
CheckCircularDependencyRecursive(x.ParameterType, stack);
}
}

if (injectTypeInfo.InjectMethods != null)
Expand Down

1 comment on commit 4325761

@vercel
Copy link

@vercel vercel bot commented on 4325761 Feb 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.