使用DI MVC增长控制器构造函数

时间:2019-05-15 21:01:06

标签: c# asp.net-mvc dependency-injection ninject

我有一个控制器,该控制器的方法与按钮绑定在一起,这些按钮对单个数据收集执行不同的处理,但是它一直在缓慢增长。甚至没有为每个数据集合都调用发送文件方法。有时,只需要三分之一,但是我们希望每种文件格式在客户端上都有自己的按钮。

public AController(
        ILogger logger,
        IabcRepository abcRepo,
        IFileService<FileTypeA> fileTypeAService,
        IFileService<FileTypeB> fileTypeBService,
        IFileService<FileTypeC> fileTypeCService,
        IPrintService printFileService,
        ....
        )

public ActionResult SendFileA(int id)
{
   _fileTypeAService.SendFile(id);
   _abcRepo.Update(id)
   _logger.Log("log message");
}

public ActionResult SendFileB(id)
{
   _fileTypeBService.SendFile(id);
   _abcRepo.Update(id)
   _logger.Log("log message");
}

public ActionResult SendFileC(int id)
{
   _fileTypeCService.SendFile(id);
   _abcRepo.Update(id)
   _logger.Log("log message");
}

public ActionResult PrintFileC(int id)
{
   _printFileService.PrintFile(id);
   _abcRepo.Update(id)
   _logger.Log("log message");
}

这些方法都是在前一种方法的基础上调用的,只有在前一种方法成功工作的情况下,才允许用户单击按钮。

文件类型A,B和C的格式不同,并且打印的文件不是这些文件中的任何文件。

这是否需要重构?这样做的最佳方式/方法是什么?

0 个答案:

没有答案