IoC和管理接口 [英] IoC and managing interfaces

查看:182
本文介绍了IoC和管理接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个使用IoC来实现数据访问库的业务对象库。我应该在哪里定义数据访问接口?它属于哪个库?或者它应该只在一个单独的库中用于接口?

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?

推荐答案

我将在业务域中定义接口。然后,接口的实现将在引用业务域的库中(并由应用程序上下文引用,或由应用程序上下文引用的IoC库引用)。

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.

在.NET项目中结构它看起来像这样:

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


域逻辑项目

    (什么都没有引用)

    域模型

    存储库接口

   ;   IoC服务定位器界面

存储库项目

    (参考域逻辑项目)

  ;   存储库实现

IoC项目

   &nbs p;(参考域逻辑项目)

    (参考资料库项目)

     IoC服务定位器实施

     IoC Bootstrapping

申请项目

    (参考资料IoC项目)

    (参考域逻辑项目)

    (可能需要引用Repository Project,不确定)

    实现与域模型交互的UI

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

这篇关于IoC和管理接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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