抽象类是否像接口一样使用StructureMap? [英] Does an abstract class work with StructureMap like an interface does?

查看:144
本文介绍了抽象类是否像接口一样使用StructureMap?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是StructureMap的忠实粉丝,几乎可以用于我所做的一切。我只使用它与接口。我想知道是否有人有使用抽象类的经验?或者...它不支持这种类型的布线?如果你有这个工作,你可以发一个例子吗?

I am a big fan of StructureMap and use it in just about everything I do. I have only ever used it with interfaces though. I was wondering if anyone had any experience using with abstract classes? or...does it not support that type of wiring? If you got this to work can you post an example?

谢谢!

推荐答案

是的,抽象类的工作方式与接口完全相同。

Yes, abstract classes work exactly the same way as interfaces.

如果WorkerBase是一个抽象类,而RealWorker是一个实现,那么:

If WorkerBase is an abstract class, and RealWorker is an implementation, then:

var container = new Container(x => x.For<WorkerBase>().Use<RealWorker>());
var worker = container.GetInstance<WorkerBase>();

这篇关于抽象类是否像接口一样使用StructureMap?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆