是否可以使用 Resharper 重构代码,以便将以下方法Eat
提取到单独的类中,并将新提取的Dinner
类作为外部依赖注入到类中?
原始代码
public class Dinner
{
public Dinner()
{
}
public void Eat()
{
//do the eating
}
}
重构代码
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();
}
}
它不必与重构的代码完全一样——这可以给出一个想法。