我们想在我们的asp.net核心mvc Web应用程序中使用swagger。因为我们使用IoC在我们的控制器中注入所需的实例,所以swagger无法构建swagger UI。当我删除构造函数时,它工作正常。
是否有人在控制器内部使用带有构造函数的swagger有想法或解决方法?
[Route("TestNamesapce/TestService/2017/08/[controller]")]
public class TestController: FullController
{
private readonly IMaintenanceTaskProvider _provider;
private readonly MaintenanceServiceConfiguration _config;
private ILog _log;
private MessageWorker _worker;
/// <summary>
///
/// </summary>
/// <param name="log">The log.</param>
/// <param name="eventing">The eventing.</param>
/// <param name="worker">The worker.</param>
/// <param name="options">The options.</param>
/// <param name="context">The context.</param>
public TestController(ILog log, IEventingClient eventing, IFileManagementClient fileManagement, MessageWorker worker, IMaintenanceTaskProvider provider, IOptions<Configuration> options) : base(log, eventing, fileManagement)
{
_config = options.Value;
_log = log;
_provider = provider;
_worker = worker;
}
/// <summary>
/// Gets the internal license identifier.
/// </summary>
/// <returns></returns>
[HttpGet("GetInternalLicenseId")]
public string GetInternalLicenseId()
{
return "abcdefghijklmnop";
}
答案 0 :(得分:1)
作为一种变通方法,您可以添加一个默认构造函数,仅用于此目的。虽然我也希望看到更好的解决方案。