We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
假定有如下代码
UI Conteroller - MeowScreen(热更工程)
MeowScreen
public class MeowScreen : XUIBehaviour { [Inject] public ISeyanaService Seyana { get; set; } }
服务 SeyanaService(热更工程)
SeyanaService
public class SeyanaService : ISeyanaService { [Inject] public IUIKit UIKit { get; set;} }
现象是:
在热更工程中,当我们打开UI并传入MeowScreen的对象时,MeowScreen中的Seyana会被依赖注入容器正确的赋值,而SeyanaService中的UIKit属性则为空,即依赖注入赋值失败。
Seyana
UIKit
初步分析,原因是通过UIKit打开UI时,走的是TinaX内部定义的依赖注入方法,这个方法对热更工程有特殊处理,所以没啥问题。 而ISeyanaService作为MeowService的依赖项,在MeowService处理依赖注入时,会被依赖注入容器(内部实现是CatLib)直接实例化并完成依赖注入,没走到TinaX重写的方法上去。而CatLib自身是不认识ILRuntime热更工程里的类的,于是SeyanaService 里面的[Inject]就没被识别出来,也就没走依赖注入流程。
ISeyanaService
MeowService
CatLib
[Inject]
说起来,刚刚看了CatLib官方对ILRuntime支持的Demo,好像也没特殊处理这些东西( https://github.com/CatLib/CatLib.ILRuntime/blob/master/src/ILRuntimeApplication.cs) ,比较神奇,后面得把CatLib的源码好好研究下。
虽然大概知道是怎么回事,但是由于作者空闲时间有限,暂时不能立即去修复好这个问题。以下是一些临时回避这个问题的方法:
public class SeyanaService : ISeyanaService { private IUIKit m_UIKit; public SeyanaService(IUIKit uikit){ m_UIKit = uikit; } }
总是就是类似 .NET CORE 默认依赖注入容器那样,咱先当属性注入的功能不存在,先用构造函数注入方式好了。
public class SeyanaService : ISeyanaService { [Inject] public IUIKit UIKit { get; set;} public void DoSomething(){ if(UIKit == null) XCore.GetMainInstance().Services.Inject(this); } }
这儿调的是TinaX内部对ILRuntime优化过的依赖注入方法,所以可以正常运作。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
问题
假定有如下代码
UI Conteroller -
MeowScreen
(热更工程)服务
SeyanaService
(热更工程)现象是:
在热更工程中,当我们打开UI并传入
MeowScreen
的对象时,MeowScreen
中的Seyana
会被依赖注入容器正确的赋值,而SeyanaService
中的UIKit
属性则为空,即依赖注入赋值失败。原因
初步分析,原因是通过
UIKit
打开UI时,走的是TinaX内部定义的依赖注入方法,这个方法对热更工程有特殊处理,所以没啥问题。而
ISeyanaService
作为MeowService
的依赖项,在MeowService
处理依赖注入时,会被依赖注入容器(内部实现是CatLib
)直接实例化并完成依赖注入,没走到TinaX重写的方法上去。而CatLib
自身是不认识ILRuntime热更工程里的类的,于是SeyanaService
里面的[Inject]
就没被识别出来,也就没走依赖注入流程。说起来,刚刚看了CatLib官方对ILRuntime支持的Demo,好像也没特殊处理这些东西( https://github.com/CatLib/CatLib.ILRuntime/blob/master/src/ILRuntimeApplication.cs) ,比较神奇,后面得把CatLib的源码好好研究下。
临时的规避方案
虽然大概知道是怎么回事,但是由于作者空闲时间有限,暂时不能立即去修复好这个问题。以下是一些临时回避这个问题的方法:
使用构造函数注入
总是就是类似 .NET CORE 默认依赖注入容器那样,咱先当属性注入的功能不存在,先用构造函数注入方式好了。
手动调一下依赖注入
这儿调的是TinaX内部对ILRuntime优化过的依赖注入方法,所以可以正常运作。
The text was updated successfully, but these errors were encountered: