views:

54

answers:

1

Hello Stackers :)

I have implemented the Unity DI in a project of mine, but I have, what I believe is a simple question.

My DataContext:

public partial class AuctionDataContext : DataContext {
  public Table<AuctionItem> AuctionItems;

  ...
 }

Some code for inserting an AuctionItem in the database. Please notice how I cast the interface to the actual type. This is for everything to work correct with the DataContext.

 public void Insert(IAuctionItem item) {
  _dataStore.DataContext.AuctionItems.InsertOnSubmit((AuctionItem)item);
  _dataStore.DataContext.SubmitChanges();
 }

Neither the AuctionItem nor the DataContext type is ever exposed to the client code but are only accessible inside the database layer. I guess my question is, is this an ok architecture ?

+1  A: 

Your architecture is "ok", but all architectures are contextual, in that one pattern might be perfect in one situation but horrible in another.

Pattern wise it is always smart to abstract your Repository/DAO from the persistence mechanism, and from what i can see you have done that. I do suggest that you another interface around your implementation that would give you the flexibility to change implementation.

 public interface IRepository<T>{
    void Insert(T item);
 }

 public class AuctionItem : IRepository<IAuctionItem> {

   public void Insert(IAuctionItem item) {
      _dataStore.DataContext.AuctionItems.InsertOnSubmit((AuctionItem)item);
      _dataStore.DataContext.SubmitChanges();
   }

 }
Nix