【发布时间】:2011-04-28 13:53:51
【问题描述】:
假设我的几个控制器构造函数采用接口 - IPeInterface IPetInterface 的具体实现有 3 种。
您将如何配置 StructureMap 以根据需要它的控制器提供具体实现之一。
粗略的例子....
class DogStuff: IPetInterface{}
class CatStuff: IPetInterface{}
class GiraffeStuff: IPetInterface{}
class DogController : Controller
{
DogController(IPetInterface petStuff)
// some other stuff that is very unique to dogs
}
class CatController : Controller
{
CatController(IPetInterface petStuff)
// some other stuff that is very unquie to cats
}
【问题讨论】:
-
虽然我确信它可以使用 StructureMap 完成(我自己更喜欢 Unity,所以我不确定如何使用 StructureMap 来完成)你确定你的设计是正确的?根据您的描述,界面可能太通用....
-
@BFree:可能太笼统了。目前我对每个“宠物”都有单独的接口,但它们是相同的,所以我想知道这是否可能/值得
标签: c# asp.net-mvc-3 structuremap