Skip to content

Commit

Permalink
fix: null reference in DI Get
Browse files Browse the repository at this point in the history
  • Loading branch information
labbbirder committed Nov 15, 2023
1 parent 4c7104b commit f50d256
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions Runtime/ClassicalUsages/ServiceContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,16 @@ static Info GetInfoWithCache(Type desiredType, Type declaringType)
Info info;
if (lutInfos.TryGetValue((desiredType, declaringType), out info)) return info; // first in order

foreach (var interfType in declaringType.GetInterfaces())
if (declaringType != null)
{
if (lutInfos.TryGetValue((desiredType, interfType), out info)) return info;
}
for (var curType = declaringType.BaseType; curType != null; curType = curType.BaseType)
{
if (lutInfos.TryGetValue((desiredType, curType), out info)) return info;
foreach (var interfType in declaringType.GetInterfaces())
{
if (lutInfos.TryGetValue((desiredType, interfType), out info)) return info;
}
for (var curType = declaringType.BaseType; curType != null; curType = curType.BaseType)
{
if (lutInfos.TryGetValue((desiredType, curType), out info)) return info;
}
}

if (lutInfos.TryGetValue((desiredType, null), out info)) return info; // default cache
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "com.bbbirder.injection",
"displayName": "Unity Injection",
"description": "Unity注入模块,可以运行时改变被注入函数实现。",
"version": "1.3.17",
"version": "1.3.18",
"hideInEditor": false,
"author": "bbbirder <502100554@qq.com>",
"dependencies": {
Expand Down

0 comments on commit f50d256

Please sign in to comment.