1

We want to use swagger with in our asp.net core mvc web application. Because we use IoC to inject required instances in our controller, swagger is not able to build the swagger UI. When I remove the constructor it works fine.

Does anybody have an idea or an workaround using swagger with a constructor inside the controller?

[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";
    }
2
  • 1
    Let's see the code, please. Commented Oct 18, 2017 at 7:14
  • Are you sure that's the reason? All of my controllers don't have a parameterless constructor and use Dependency Injection. The constructor isn't actually even used for the swagger.json file. It uses the ApiExplorer (at least on ASP.NET Core) Commented Oct 18, 2017 at 12:26

1 Answer 1

0

As a workaround, you could add a default constructor to be used for this purpose alone. Though I would also prefer to see a better solution.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.