且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用IoC容器时如何管理接口隔离?

更新时间:2023-10-24 07:54:52

我没有找到如何以重复方式结束我的问题...但是我确切地找到了如何解决另一个***问题中所需的事情.

Mark在Windsor中提到的F​​orward方法,它也存在于StructureMap中……看来这是做事的正确方法.

StructureMap单例用法(实现两个接口的类)

Possible Duplicate:
StructureMap singleton usage (A class implementing two interface)

I'm currently designing a small system and i'm currently using structureMap as IoC. I just recently got the point of interface segregation...and I'm wondering now.

If I have a certain business object, that will implement say, three interfaces... how should I handle this in the configuration and instatiation of code?

Assuming I have two interfaces in a simple scenario, for a service layer class called EmployeeServiceObject. IGenericEntity and IEmployeeServiceObject.

GenericEntity will provide the CRUD capabilities for the class, and IEmployeeServiceObject will provide resultsets for business queries/operations.

If on a Facade/Service Layer method, I have to use the EmployeeServiceObject class and actually use functionality from both interfaces...how should this be handled?

Initially I thought that the correct thing was to setup the configuration of the IoC to map IEmployeeServiceObject to EmployeeServiceObject, ask the factory for the object, and just cast it to IGenericEntity when i needed to use the CRUD functionality, but i'm not quite sure. It also does not seem right because I'd never be formally stating that the concrete class is actually implementing the interface that was not setup in the ioc container configuration.

and I definitely know that creating two instances of the same concrete class but asking for a different interface...sounds even worse.

How should this be handled?

I didnt find how to close my question as duplicate...but I found exactly how to do what I needed in another *** question.

What Mark mentioned as the Forward method in Windsor, it also exists in StructureMap...and it appears it would be the right way to do things.

StructureMap singleton usage (A class implementing two interface)