I have an EF-driven Repository pattern implementation. Roughly looks like this:
public class DataRepository : IDataRepository
{
public IDbSet<Contacts> Contacts { get; set; }
}
I would like to implement a Contact import functionality, which has some custom logic for manipulating the entity which is being imported (i.e. it is different from Adding an entity to the repo).
I see two options right now:
Implement an extension method on the
IDbSet<Contacts> Contacts
, which would allow me to do:dataRepository.Contacts.Import(contact);
dataRepository.Save();
Implement a static method on the
Contact
class, which will then allow me to do something like:Contact.Import(contact);
but then I am not sure how I would attach the entity to the context, without breaking my abstraction...
I could also implement an 'Import Service' which wraps this functionality, but it seems very old-school. e.g.:
public class ContactsImportService
{
public ContactsImportService(IDataRepository dataRepo)
{
...
}
public void Import(Contact contact)
{
// Manipulate contact here
this.dataRepo.Add(contact);
this.dataRepo.Save();
}
}
Any thoughts?