开发者

Multiple DBContexts with UnitOfWork and Repositories?

How can i create multiple dbcontexts and how to adress this to a repository to use?

My current example is based on MyFinance, codeplex application , so this means you should be able to view the source here . Does anyone have an idea, i think i should change the UnitOfWork, RepositoryBase, IDatabaseFactory, ... but i'm not sure how or with what.

Thanks in advance

More information than above ^^

The following situation is like this, because we have a insane large "incremental" ammount of data, we would have one master dbcontext (MyMasterContext), with only the Users, their roles and information and ot开发者_JS百科her details.

Next, we would initially have 1 server, but we suspect this would change during the next 4-6 months, this is why we have our next dbContext named: MySlaveContext.

Also, for the sake of speed, we have 1 other server that only returns JSON Requests (MyAjaxContext), for example, giving the next 10 cities with the current zipcode, and many other "autocomplete" functions.

How do you mean, i shouldn't use unitOfWork? Updating an object on Asp.Net MVC does use the UnitOfWork pattern, doesn't it? (UpdateModel(object) & saveChanges).

I'll look into TransactionScope, but i'd like to use the UnitOfWork if possible. And do you have any examples or something on how i should solve my current problem?


That project do not have a unit of work implementation (other than the EF4 context) or a IDatabaseFactory.

I would use TransactionScope instead of a unit of work implementation and just reference the proper (in the constructor) EF4 DbContext in each repository implementation.

Update in the response to the comment

I don't see any benefit in using generic repositories or a unit of work implementation if you are only working with databases.

Create repositories that have what you need, no more or less (with a corresponding interface which you reference). It's perfectly fine for your repository implementations to take in a EF DbContext.

Use TransactionScope if you need transaction support.


I'd suggest you check out NCommon. It provides an implementation for patterns such as the repository, unit of work and specification pattern. It also supports multiple contexts and multiple units of work.

You can find more documentation here:

http://riteshrao.github.com/ncommon/index.html

The documentation seems to be done right now. Hopefully that will get fixed.

Found an old blog post from the author about NCommon and support for multiple database here:

http://codeinsanity.com/archive/2010/04/05/unit-of-work-implementation-in-ncommon-1-1.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜