1
我具有接收在其构造,这通常是创建它的对象的类型,例如另一种类型的一个类型:如何获得在Unity中注入的对象的类型?
public class Logger {
public Logger(Type parent) { ... }
}
我想指示统一解决Logger
传递作为参数传递给它的构造函数需要它的对象的类型。喜欢的东西:
// ... would be some directive to tell Unity to use the type that
/// depends on Logger
container.RegisterType<Logger>(new InjectionConstructor(...));
所以,当我尝试解决MyService
:
public MyService {
public MyService(Logger logger) { ... }
}
则回复:
var logger = new Logger(typeof(MyService));
return new MyService(logger);
这可能吗?还有另一种方法吗?