我有这样的课:
public class MyClass
{
public MyClass(IService service)
{
this.Service = service;
this.Dependency = new Dependency(service);
}
}
我想将new Dependency()
调用移至构造函数。
public class MyClass
{
public MyClass(IService service, IDependency dependency)
{
this.Service = service;
this.Dependency = dependency;
}
}
我不知道如何绑定它,以便使用构造函数参数IDependency
创建它。service
Bind<IDependency>()
.To<Dependency>()
.WithConstructorArgument("service", ctx => ctx.???); // How do I do this?