Replace factory with AutoFac
I'm accustomed to creating my own factories as shown (this is simplified
for illustration):
public class ElementFactory
{
public IElement Create(IHtml dom)
{
switch (dom.ElementType)
{
case "table":
return new TableElement(dom);
case "div":
return new DivElement(dom);
case "span":
return new SpanElement(dom);
}
return new PassthroughElement(dom);
}
}
I'm finally getting around to using an IoC container (AutoFac) in my
current project, and I'm wondering is there some magic way of achieving
the same thing elegantly with AutoFac?
No comments:
Post a Comment