I'm trying to write reusable components for my most common dev scenarios:
I have made a general purpose presentation-layer to present domain-objects and data-objects (dc-serializable) to be encapsulated in the domain-objects. I also have some kind of domainstate/context where I keep all my domainobject-instances referenced. The idea is that the domain-objects have special collections that get populated from the datasource when they are first accessed, on-demand. It's not exactly "DDD" I think but it seem to work...
Anyway, now I'm stuck on the datacontext and datasource-part. I've been thinking a lot on how to store data and interact with the datasource; xml in zip-files, sql-server, sql-lite-files, entity framework, nhibernate, linqtosql, mongodb etc and I can't decide what to use. It appears I need to abstract away both the datasource and the datacontext and instead decide what to use in each application. The important thing is that I don't embed any hard dependencies on specific frameworks.
Is it realistic to abstract away the datacontext and datasource and still have it work well and easy with all kinds of existing frameworks out there? Am I thinking about this wrong? Is this a dead end?
All I want and need (I think) is my domainstate to be able to query the datacontext for objects matching certain criterias. I'm not sure if it should be able to work with entire object graphs or only individual data-objects, or not even concrete types but some generic objects only, or if they should be cloned for each request or not. I feel very confused when I start thinking about this...
Gahhh
Update:
I see a DataContext/DatabaseContext (for instance EntityFramework) as a module/layer to keep objects cached in memory, execute queries, fetch and store data from/to whatever datasource and return typed objects to the consumer. Is this right?
Whats the difference of the Repository-pattern (DDD) and my DataContext?
Update 2:
Basically, this is my model (good or bad?):
DataSource->DataContext/DataObject->DomainState/DomainObject->Presenter