【发布时间】:2015-04-29 07:33:43
【问题描述】:
我有一个类在构造函数中接收接口和字符串参数:
public MyClass(IService service, string config) : IMyClass
在Autofac中,接口被注册:
builder.RegisterType<Service>()
.As<IService>()
.InstancePerRequest();
MyClass 也注册了WithParameter 方法用于字符串参数:
builder.RegisterType<MyClass>()
.As<IMyClass>()
.WithParameter("config", parameters["Config"]);
但是如何将IService接口已经解析的对象传递给MyClass构造函数呢?
我原以为上面使用IService注册就够了,但是当使用WithParameter方法时,我显然需要以同样的方式声明所有参数。
【问题讨论】: