Please review this design, maybe IUnitOfWork is flawed

Topics: Developer Forum
Oct 8, 2006 at 11:15 PM
All the code that call a member of IUnitOfWork know at design-time the entity type of the arguments and the return types. Nevertheless a call at run-time to a member of IUnitOfWork can result in an InvalidCastException.

This can be improved coming to a complete compile-time type check.
Something like this:

class NorthwindEntitiesUnitOfWork
public IList<Customer> GetAllCustomers() {
// ...

public IList<Product> GetAllProducts() {
// ...

// ...

Do you see any reason to have a generic IUnitOfWork that don't know the northwind db entities?

Oct 8, 2006 at 11:49 PM
More on this, I feel that it is not a responsability of UnitOfWork the persistence opertions to/from the db.

The responsability of UnitOfWork should be to coordinate reading and writing of all object instances involved in the same bussiness transaction.

IMO the persistence operazions should be placed i.e. in CustomerPersistenceService.cs (ManagedDesign.Northwind assembly).