I have an application. This application uses an interface to access the database. This interface can be implemented by many classes. For example, one uses EF 4.4, but other classes can use EF5, which is more efficient. In the future, perhaps I will use EF6 because it uses async methods. In this example, all methods use EF, but perhaps other parameters can be used in other ways.
The application is encoded once using the interface and in accordance with the configuration file uses one implementation or another, so I only need to change the code in one place, the constructor, to add a new parameter to the instance of the class assigned to the interface.
Currently all class methods are not async , but in the future, if I use EF6, I would like to use async methods, so I don’t know if it is possible that a class that uses EF6 and implements the interface can use async methods.
For EF6 asynchronous methods, I would use the async / awiat template, so in my class method I need to use the async attribute. This allows me to use the await keyword when I call the async method for EF6.
But can this class implement an interface that is designed for synchronous methods for the first time?
Is there a way that in the main application I can use many implementations without having to change the code? Some implementations will use asynchronous methods, while others will be synchronous.
c # interface async-await
Álvaro García Nov 26 '12 at 21:34 2012-11-26 21:34
source share