3
votes

My actual case is I've allowed dependency injection using parameter binding on API controllers implementing a custom parameter binding.

For example, a controller action may look as follows:

public async Task<IHttpActionResult> GetByIdAsync(Guid id, ICustomerFacade customerFacade)

When I explore my API using Swagger UI generated by Swashbuckle, customerFacade is specified as an actual and required resource action parameter.

Do you know any way of excluding controller action parameters from generated Swagger UI?

Note: I know that a workaround could be injecting dependencies using constructor injection, but I still prefer to be able to both do constructor and regular method dependency injection.

1

1 Answers

0
votes

I'm not positive but I think you should be injecting the dependency into the controllers constructor and not the Get method.

So, your class would have:

private ICustomerFacade _customerFacade;

public MyController(ICustomerFacade customerFacade)
{
     _customerFacade = customerFacade;
}

public async Task<IHttpActionResult> GetByIdAsync(Guid id){
     return Ok(_customerFacade.getCustomer(id));
}

Unless you want the client calling your api to be responsible for injecting the customerFacade...