为了从Autofac迁移到DryIoc,我遇到了一种情况,我需要将参数值传递到服务的构造函数中。
// given the following class
public class SomeService
{
public SomeService(Foo foo, Bar bar) { }
}
// in autofac it looks like this
container.RegisterType<SomeService>()
.WithParameter("foo", SomeFoo.Value)
.WithParameter("bar", SomeBar.Value)
.AsSelf();
DryIoc中的等效值是什么?
目前,我正尝试使用RegisterDelegate
,但不确定是否在正确的路径上。
container.RegisterDelegate(x => new SomeService(SomeFoo.Value, SomeBar.Value));
container.Register<SomeService>(
made: Made.Of(Parameters.Of
.Name("foo", _ => SomeFoo.Value)
.Name("bar", _ => SomeBar.Value)));
这里可能是重载:https://www.fuget.org/packages/DryIoc.dll/4.2.0/lib/netstandard2.0/DryIoc.dll/DryIoc/Parameters
Parameters
类类似于PropertiesAndFields
类,用于指定属性注入详细信息。
此外,您可能对https://www.fuget.org/packages/DryIoc.Syntax.Autofac.dll感兴趣的是DryIoc.Syntax.Autofac包>
从V1开始,它仅涵盖了Autofac API表面的一小部分,但我鼓励您研究其源代码,并可能在第二方面提供帮助:https://github.com/dadhi/DryIoc/tree/master/src/DryIoc.Syntax.Autofac