Im have implemented the repository pattern in my application. The interface is as follow:
public interface IRepository<T> where T : class
{
void Insert(T entity);
void Delete(T entity);
IEnumerable GetAll();
// and more...
}
The default implementation of the repository is on Entity framework repository pattern. So that if i want to consume my service with a repository(that is already in a ddl, like an API) i do this:
var uService = new UserService(new EFRepository<User>(new Context()));
My situation is that have a model that will required to add a new property called situation to that model but is only for one client of the company. That property will not need to exists for the others.
What i did was this:
class MyCustomModel : User{
public int Situation { get; set;}// new property
}
//mean while in another class
UserService bService = new UserService(new EFRepository<MyCustomModel>(new Context()));
But 2 things happend:
Since the
UserServicerequires a repository of typeUserwill fail, because model is not type expected that isUser.If some magic occured and worked and no type of model was changed on the
UserService, the new property wont be seen in the implementation of the UserService because the model still being type ofUser
The Why im asking for an alternative
The ddl is already developed and i dont want to add a new DbSet to the database context in case im using the EF repository only because of one client.
I like to avoid the fact that i need to add the new property to the User model only because(again), one client.
The UserService already recive the IRepository<User> implementation and changing that to MyCustomModel will required alot of time in all this cases I've mentioned.
Its there another way(like other pattern) of solving this situation here? Am I doing something wrong?
I tried with the visitor pattern but i dont see anyway that i can make it work with it.
Anything will be appreciated.
Aucun commentaire:
Enregistrer un commentaire