I'm also late to the party, for which I apologise.
@Daniloloko, if I understand correctly you want to:
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
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.
@Daniloloko, if I understand correctly you want to:
- Use Unity to do dependency injection
- Have two different data contexts, each of which implement
IDataContextAsync
-
Decide within any given method, or even per line of code, which data context to use
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.