views:

63

answers:

4

I have an ecomm application in Project#1.

I have a payment gateway implementation in Project#2 that references Project#1. It references interfaces so that the gateway is implemented to a contract.

Now I need to actually use the implementation from Project#2 in Project#1.

There is a circular dependency so it isnt' working as it is.

What shall I do? Should I break the interfaces into their own project? That seems like the easiest approach.

The point is that if I need to create another implementation of a gateway, it can easily be incorporated into Project#1.

A: 

Yes. You should put the interfaces that the plugins should implement (along with any potential common helper code) in a separate assembly.

Nick
A: 

Yes, break your interfaces into another project and reference that project from both. This way, both are dependent upon an abstraction.

Craig Wilson
+1  A: 

Putting interfaces in a separate library is often a good idea. It also ensures that you can vary and deploy concrete implementations independently of each other.

As a general rule of thumb, when I design, I start by putting the interfaces together with their consumers, and I then move them to a separate library if the need arises.

As far as I understand your description, you have consumers in each library, so moving them sounds like the correct approach.

If you find that these interfaces are sufficiently unrelated, you may even want to consider putting them in two different libraries.

Mark Seemann
what would you use as a namespace for just interfaces?
mrblah
ah, now I need to reference enums in my interface project sheesh!
mrblah
Namespaces: in many cases you could say that the interfaces represent the real model (the rest is just implementation details), so you may want to name it accordingly.
Mark Seemann
Enums are code smells anyway. Refactor them to polymorphic types instead.
Mark Seemann
A: 

This is a dupe of your other question, but it at least has more detail.

If Project 2 is a plugin to Project 1, then Project 1 should not have any dependencies on Project 2, under any circumstances. Period.

Load Project 2's assembly into Project 1 via reflection/MEF/etc.

kyoryu