Unity 寄存器类型映射是否丢失?
这类似于这个问题,但答案并不不能解决我的问题。
我想在代码中注册接口的默认实现,但能够在代码运行之前读取的配置中覆盖它。
我想做一些类似
if (!container.IsImplementationRegistered(typeof(TInterface))
{
container.RegisterType<TInterface, TImplementation>();
}
我不能使用 TryResolve 的事情,因为我将连续注册几种类型,这些类型可能具有尚未注册的自己的依赖项,从而导致错误的覆盖。
Unity 2.0 会启用此功能还是有办法在 1.2 中实现此功能?
This is similar to This question but the answer doesn't solve my problem.
I want to register a default implementation for an interface in code but be able to override that in a config that is read BEFORE the code is run.
I want to do something like
if (!container.IsImplementationRegistered(typeof(TInterface))
{
container.RegisterType<TInterface, TImplementation>();
}
I can't use TryResolve as I will be registering several types in a row that might have dependencies of their own that aren't yet registered, leading to an erroneous override.
Will Unity 2.0 enable this or is there a way to do it in 1.2?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许你可以尝试使用子容器。
如果子容器无法解析类型,Unity 将转到父容器进行解析。
Maybe you can try with a child container.
If the child container cannot resolve a type, Unity goes to the parent container to resolve.