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
  •  | 
  •  

문제

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

도움이 되었습니까?

해결책

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
}

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top