Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有一堂课
public class Foo{ @Inject public Foo(MessageBus messageBus, SomeServiceAsync service){ ... } ...
考虑到要注入构造函数参数,我对如何构造这样的类有些怀疑。或者我必须以某种方式通过 Gin 获取 Foo 类的实例(无论如何都要进行注入)?
提前致谢
你的假设是正确的。Foo如果您希望它们的构造函数被注入,您必须从 Gin 中获取所有s。要从 Gin 中获取 a Foo,您需要将其注入到其他东西中,或者使用Ginjector. 通常,您只会从 a 中获取一个类的实例(或少数类的实例)Ginjector,并依赖 Gin 来注入它们的所有依赖项,以及它们的依赖项的依赖项,等等。Gin 教程是一个很好的起点。
Foo
Ginjector