Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8902377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:35:51+00:00 2026-06-15T01:35:51+00:00

I have an application. This application uses an interface to access the database. This

  • 0

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 that is more efficient. In the future perhaps I will use EF6 because it uses async methods. In this example all the methods use EF, but perhaps other options can be use other ways.

The application is coded once, using the interface, and according to the config file, use one implementation or the other, so I only need to modify the code in one place, the constructor, to add the new option in the instantiation of the class that is assigned to the interface.

At the moment all the methods of the classes are not async, but in the future if I use EF6 I would like to use the async methods, so I don’t know if it is possible that the class that use EF6 and implements the interface can use the async methods.

For the async methods of EF6, I would use the async/awiat pattern, so in the method of my class I need to use the async attribute. This lets me use the await keyword when I call to the async method of EF6.

But this class can implement the interface that in a first time is for synchronous methods?

Is there some way that in the main application I can use many implementations without the need to modify the code? Some implementations will use async methods while others will be synchronous.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:35:53+00:00Added an answer on June 15, 2026 at 1:35 am

    async isn’t a part of the signature, so you don’t actually need to be concerned with whether the method implementing the interface is async or not, you only need to be concerned with the types of the properties, the return type, the name of the method, and the accessibility.

    The real difference is that your async methods will need to return a Task or a Task<T>, whereas the non-async methods are most likely currently returning void or some type, T directly.

    If you want to “future proof” your application one option is to ensure that all of your interfaces return Task or Task<T> and that for your EF4/EF5 implementations you wrap your results in a completed task even though they’re executed synchronously.

    Task.FromResult was added in .NET 4.5, but if you don’t have it you can write your own easily enough:

    public static Task<T> FromResult<T>(T result)
    {
        var tcs = new TaskCompletionSource<T>();
        tcs.SetResult(result);
        return tcs.Task;
    }
    

    You can also write a CompletedTask method that simply returns a task that has already completed: (It caches a single task for efficiency reasons.)

    private static Task _completedTask;
    public static Task CompletedTask()
    {
        return _completedTask ?? initCompletedTask();
    }
    
    private static Task initCompletedTask()
    {
        var tcs = new TaskCompletionSource<object>();
        tcs.SetResult(null);
        _completedTask = tcs.Task;
        return _completedTask;
    }
    

    Those two methods will simplify the process of having all of your methods returning some type of Task, although doing this will make your code a bit messier until you’re able to use C# 5.0 to be able to await the result.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one proprietary software my office uses for database access and reporting which
I have an application written in a language called magic. This application uses MSSQL
I have a Web Service and an Android application that uses this web service.
I have an application App1 which defines class A and uses instances of this
I have an application that uses the .NET framework 3.5. I am building this
I have compiled a .NET application using Any CPU option. This .NET application uses
I have a small application that uses WCF to communicate with a webserver. This
I have a web application that uses a library which resides in TOMCAT_HOME/common/lib. This
This is getting me quite confused: I have a small application that uses a
I have this part of script from my GAE application which uses webapp2, which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.