IoC and managing interfaces

醉酒当歌 提交于 2019-12-12 10:11:27

问题


Say I had a business object library which was using IoC to implement a data access library. Where should I define the Data Access Interface? Which library does it belong? Or should it be in a separate library just for interfaces?


回答1:


I would define the interfaces within the business domain. Then the implementations of the interfaces would be in a library that references the business domain (and is referenced by whatever the application context is, or by an IoC library which is referenced by the application context).

Then swapping out one implementation with another is just a matter of creating another library and swapping the reference in the application context.

In a .NET project structure it would look something like this:

Domain Logic Project
    (references nothing)
    Domain Models
    Repository Interfaces
    IoC Service Locator Interface
Repository Project
    (References Domain Logic Project)
    Repository Implementations
IoC Project
    (References Domain Logic Project)
    (References Repository Project)
    IoC Service Locator Implementation
    IoC Bootstrapping
Application Project
    (References IoC Project)
    (References Domain Logic Project)
    (May need to reference Repository Project, not sure)
    Implements UI which interacts with Domain Models



来源:https://stackoverflow.com/questions/5384246/ioc-and-managing-interfaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!