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.
You can do it nearly as you want in R# 7 using three-step refactoring:
All that is left is to fix a constructor in Dinner class so it would get IEatService as a parameter.