How to use common method for example AddUser with domain objects OldVersionProject.User and NewVersionProject.User

StackOverflow https://stackoverflow.com/questions/19359986

  •  30-06-2022
  •  | 
  •  

Question

I mean that I have two objects for which number of variables and names completely the same with only 1 difference that they are stored in two different assemblies.

Is it possible to mark somehow the dll that it is the same objects, so I could use "User" object from the old project and "User" from the new project with the same common service AddUser

Was it helpful?

Solution

This is screaming out for an interface

namespace OldVersionProject
{
    public class User : IUser
    {
    }
}

namespace NewVersionProject
{
    public class User : IUser
    {
    }
}

public interface IUser
{
    // common properties
}

Then in your common service

public void AddUser(IUser user)
{
    // user is now version independant
}

OTHER TIPS

Extract the User class into a shared library, say, BusinessObjects, and reference that library from all projects that need a User class.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top