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 9085575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:16:42+00:00 2026-06-16T21:16:42+00:00

Is it possible to use Resharper to refactor code such that the below method

  • 0

Is it possible to use Resharper to refactor code such that the below method Eat is extracted into a seperate class, and the newly extracted class is injected in the Dinner class as an external dependency?

Original Code

public class Dinner
{
    public Dinner()
    {

    }

    public void Eat()
    {
        //do the eating
    }
}

Refactored Code

public interface IEatService
{
    void Eat();
}

public class EatService : IEatService
{
    public void Eat()
    {

    }
}
public class Dinner
{
    private readonly IEatService _eatService = null;

    public Dinner(IEatService eatService)
    {
        _eatService = eatService;
    }

    public void Eat()
    {
        _eatService.Eat();
    }

}

It doesn’t have to be exactly as the refactored code – this is shown to give an idea.

  • 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-16T21:16:43+00:00Added an answer on June 16, 2026 at 9:16 pm

    You can do it nearly as you want in R# 7 using three-step refactoring:

    1. Place the caret at your Eat method, invoke Extract Class refactoring (Ctrl-Shift-R in VS), name your class EatService.
    2. Place the caret at your EatService class, invoke Extract Interface refactoring.
    3. Place the caret at your EatService class, invoke Use Base type Where Possible refactoring.

    All that is left is to fix a constructor in Dinner class so it would get IEatService as a parameter.

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

Sidebar

Related Questions

I use code rush and refactor pro (highlight possible code issues and so on
Is it possible to use django class based generic views with a ManyToManyField relation?
In Resharper I edited the inspection severity of the 'use var keyword when possible'
ReSharper extension of VS suggest me to use PascalCase in below property. public Color
I like the fact that ReSharper suggest me to use the var keyword. Instead,
I am using ReSharper to help me spotting possible errors in my code, and,
Possible Duplicate: Why does ReSharper want to use 'var' for everything? I have ReSharper
Does anyone know if it is possible to have resharper force the use of
I have recently started looking into Google Charts API for possible use within the
Is it possible use mod_rewrite to resolve addresses hosted on another server? Say I

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.