开发者

IoC and managing interfaces

开发者 https://www.devze.com 2023-02-18 16:35 出处:网络
Say I had a busines开发者_Python百科s 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

Say I had a busines开发者_Python百科s 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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消