在 DryIoc 中,如何将字符串参数传递给工厂方法?
在 Wiki 中,有一个关于如何传递另一个注册类的示例,但我似乎无法弄清楚如何传递一个字符串。
鉴于以下情况:
public interface MyInterface
{
}
public class MyImplementationA : MyInterface
{
public MyImplementationA(string value) { }
}
public class Factory
{
public MyInterface Create(string value)
{
return new MyImplementationA(value);
}
}
public class MyService1
{
public MyService1(MyInterface implementation) { }
}
class Program
{
static void Main(string[] args)
{
var c = new Container();
c.Register<Factory>(Reuse.Singleton);
c.Register<MyInterface>(Reuse.Singleton, made: Made.Of(r => ServiceInfo.Of<Factory>(),
f => f.Create("some value") //How do I pass a string to the factory method?
));
c.Register<MyService1>();
var a = c.Resolve<MyService1>();
}
}