I have a Generic class like this :
public class Mapper<TEntity, TDataAccess>
where TEntity : Common.IEntity
where TDataAccess : DataAccess, new()
{
public TDataAccess DataAccess { get; set; }
public Mapper()
{
DataAccess = new TDataAccess();
}
/*
* ...
* */
}
and data access is like this :
public class DataAccess
{
public DataAccess()
{}
public DataAccess(string tranName)
{}
// CRUD functionality and other data access staff
}
and a inherited class form DataAccess :
public class UserDataAccess:DataAccess
{
public UserDataAccess():base(string.Empty)
{
}
public UserDataAccess(string tranName):base(tranName)
{
// Something to do with user
}
}
and finally UserMapper from Mapper :
public class UserMapper : Mapper<User,UserDataAccess>
{
// Mapping entity properties with datarows columns
}
now imagine that I need to send tranName to given TDataAccess in UserMapper. how can do this without changing DataAccess class ? I can't access the source of DataAccess and also Generics don't realize Types different constructor overloads.
I know that I can have a property on UserDataAccess and fill it whenever I need, but I can't because of thread safety issue.
The User class is a plain entity - it has only properties.