使用 AutoFac 时,您可以使用.RegisterType
将类与接口关联,但您也可以使用.Register
(它允许您通过 lambda 指定构造函数参数)。
对于具有无参数构造函数的类,这两种方法是否等效?
var builder = new Autofac.ContainerBuilder();
builder.RegisterType<MyClass>().As<IMyInterface>();
builder.Register(x => new MyClass()).As<IMyInterface>();
有没有最好使用的场景.RegisterType
?