与DryIoc中的自动传真机“ WithParameter”等效吗?

问题描述 投票:1回答:1

为了从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));
dryioc
1个回答
1
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.