Quantcast
Channel: URF - Unit of Work & (extensible/generic) Repositories Framework
Viewing all articles
Browse latest Browse all 1539

New Post: Multiple Entity Framework Contexts(Multiple database types) on the same time.

$
0
0
I'm also late to the party, for which I apologise.

@Daniloloko, if I understand correctly you want to:
  1. Use Unity to do dependency injection
  2. Have two different data contexts, each of which implement IDataContextAsync
  3. Decide within any given method, or even per line of code, which data context to use
These assumptions are important. Your solution for (2) and (3) depends on your DI framework of choice, in this case Unity. The principal is independent of your choice of DI framework: you have two concrete types that need to resolve to the same interface, so that the DI framework can inject the right type for that interface in the right place. However, how you do this depends entirely on your DI framework.

You should essentially be looking at some kind of factory pattern to help you get the correct concrete implementation when you need it, without tightly coupling yourself to the actual types DB1Context and DB2Context inside your class.

I can't point you at an obvious piece of documentation for Unity as this is a more advanced use of DI, but named registrations are a good start. See MSDN: Resolving an Object by Type and Registration Name.

Viewing all articles
Browse latest Browse all 1539

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>