Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Same interface in different domains/project

I got this issue:

Product class in a SQLBackend that implements IProduct interface.

I also got a Product in SAPBackend (ERP, accounting software) that implements the same IProduct.

Both backend is in a different project.

I want to be able to use pass a Product between this two project so I need the same common interface.

I was thinking placing IProduct in a common interface project but if had many common cases would that lead quite many interfaces in that project. And if just lead to that I expose those interfaces to quite many projects

I wonder if there is a better case so SAPBackend and SQLBackend stand by them self and still share a common interface?

namespace Interfaces
{
    public interface IProduct
    {
        string name {set; get;}
    }

}
namespace Sqlbackend
{
    public class Product : IProduct
    {
        public string name { set; get; }
     }
}
namespace ERPbackend
{
    public class Product : IProduct
    {
        public string name { set; get; }
    }
}
like image 362
user108149 Avatar asked Jun 13 '26 18:06

user108149


1 Answers

Types in .NET are scoped by their assembly. Unless the interface is in the same assembly, it is not the same type and won't be treated as such (cast will fail, etc).

So you will need a reference between projects here; most commonly, to a third dll that just has the common types and interfaces in it.

The exception to this is if you are doing contract-based SOA between the two layers (for example via WCF). But I don't think that this is what you intended.

like image 110
Marc Gravell Avatar answered Jun 15 '26 06:06

Marc Gravell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!