Unity 中温莎城堡的 DependsOn 等效项是什么?

发布于 2024-09-29 16:33:36 字数 61 浏览 1 评论 0原文

我将 DependsOn 用于静态依赖项,例如连接字符串。 Unity Fluent 界面的等效功能是什么?

I use DependsOn for static dependencies such as connection strings. What is the equivalent function for Unity's Fluent interface?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ㄖ落Θ余辉 2024-10-06 16:33:36

您可以直接在 RegisterType 调用中将该值作为参数或属性的值传递。

例如,如果您有此类:

public class Clock {
    public Clock(int startTicks) { ... }
    public Clock(DateTime startTime) { ... }
}

您可以像这样配置它:

container.RegisterType<Clock>(
    new InjectionConstructor(154324));

它会将该整数传递给采用单个 int 的构造函数。如果您传递了 DateTime,它会调用另一个构造函数。

You can just pass the value directly in the RegisterType call as the value for a parameter or property.

For example, if you have this class:

public class Clock {
    public Clock(int startTicks) { ... }
    public Clock(DateTime startTime) { ... }
}

You could configure this like so:

container.RegisterType<Clock>(
    new InjectionConstructor(154324));

and it'll pass that integer to the constructor that takes a single int. If you'd passed a DateTime instead, it'd call the other constructor.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文