问题描述
我对DI的了解不多,但是我需要使用WindsorCastle实现一个简单的工厂。
我将实施的工厂是:
public class RequestFactory
{
private Dictionary<string,IRequest> operaciones;
public RequestFactory()
{
this.operaciones = new Dictionary<string,IRequest>();
}
public void Add(IRequest operacion,string datos)
{
this.operaciones.Add(datos,operacion);
}
public IRequest Getoperation(string register)
{
return this.operaciones[register];
}
}
RequestFactory.Add("Header",HeaderRequest) //HeaderRequest inherits from IRequest
RequestFactory.Add("Body",BodyRequest) //BodyRequest inherits from IRequest
我看到这是通过以下方式完成的:
container.Register(
Component.For<IRequest,HeaderRequest>().Named("Header")
container.Register(
Component.For<IRequest,BodyRequest>().Named("Body")
但是idk如何获得它。
然后我需要致电工厂。没有DI,这将是这样的:
var request = RequestFactory.Getoperation("Header");
但是idk用DI怎么回事
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)