April 2017
Intermediate to advanced
564 pages
24h 7m
English
In an enterprise application, we may have multiple databases from where we need to perform database operations. So, rather than injecting DataContext directly into the Repository, we will create a DbFactory class and inject our DataContext through dependency injection. For example, if we have multiple data context classes pointing to different databases, we can inject them all through the parameterized constructor in DbFactory and expose properties to return their instance.
It is always better to expose interfaces, as it encapsulates the actual implementation. We will create the IDbFactory interface and then implement it using the DbFactory class.
Here is the code of the IDbFactory interface:
public interface IDbFactory ...
Read now
Unlock full access