I can't explain my problem in English. so let me show my situation.
// in Main Project
public class User
{
public int version
{
get;
set;
}
}
// in Common Project
public class Service : BaseService
{
User _user;
public void SetVersion(int versionID)
{
_user.version = versionID;
}
public bool HasMessage()
{
return GetMessage(user.version);
}
}
And now I have another sub project. and I need use Service class in there. so I wish make Service class independent from User class.
how do I do that?
I have only below solution. Is there any brilliant way?
public class Service : BaseService
{
Action<int> _getCallBack;
Func<int> _setCallBack;
public Service(Action<int> getCallback, Func<int> setCallBack)
{
_getCallback = getCallback;
_setCallback = setCallback;
}
public void SetVersion(int versionID)
{
setCallback(versionID);
}
public bool HasMessage()
{
return GetMessage(getCallback())
}
}
It depends on your use of 'User' in service. You can add an interface IUser in Common project, and have User implement it.
Then in the other SubProject, write UserSub : IUser that also implements the interface IUser.
That way Service is independent, but you'll still have to implement something in each project that uses Service. (Which you need to do anyway, because Service currently uses it as an inner variable.