views:

29

answers:

1

Hi All

I've done a bit of Linq programming with TDD ASP.Net MVC and loved it. Digressing, I'm now learning webforms against stored procs and cannot use linq. I would like to retain some of the loose coupling and testability enjoyed with MVC.

I didn't have the time to learn and setup a dependency injection infrastructure so instead I created an object factory that can be configured to create either mock or actual instances depending on what is required.

The problem with this approach is the factory serves new instances of my test repositories, so when entity A asks for the repository for entity B it gets a fresh instance without the changes made in the context of my unit test - this is the problem. Since my test instances have no persistence mechanism and I'm not using dependence injection, I need a way for the Entity A to access the current data context of my unit test so it can get the dirty repository of Entity B. For desktop apps I'd usually create my dataContext as a singleton but due to concurrency issues with web-apps I've ruled that out.

I'm looking for a nice pattern to follow instead. As a stop gap I've required that all repositories and business objects be instantiated with a data context creating a kind of hierarchy where dataContext instantiates repository with dc which in turn instantiates business objects with dc.

I've not used a composite pattern, inheritance or interfaces (except for mocking). I'm not much of an OO programmer but this looks pretty ugly. Has any one got any nice pattern suggestions I should follow that could tidy up my solution?

TIA

A: 

Look up the data mapper pattern, there should be plenty of examples out there, this is the approach we use and it works well for us.

Burt
Ok, that gives me a lead. http://martinfowler.com/eaaCatalog/dataMapper.html describes the repositories I've created but not the context issue (Maybe I need the book). "...the Data Mapper itself is even unknown to the domain layer." I'd like to know how this is achieved without loading all dependencies in the object graph at once.
Luke Rohde