I recently found an issue with NSwag.AspNetCore and the Lamar IoC library (successor to the venerable StrutureMap), where a call to UseSwagger causes an exception.
Full details are available here.
The issue is caused by NSwag.AspNetCore's unusual use of DI to resolve internal types, which can be seen here:
var documents = app.ApplicationServices.GetRequiredService<IEnumerable<SwaggerDocumentRegistration>>();
While it could be argued that this is Lamar's problem, I'm of the opinion that using DI to resolve internal types is an anti-pattern.
This can be resolved in a couple of ways:
SwaggerDocumentRegistration as publicSwaggerDocumentRegistration as more of a 'storage mechanism', than actual DI (since registrations are added in ConfigureServices using AddSwaggerDocument, so an alternative would be to not add these to the container, but use some kind of storage class insteadOption 2 obviously changes the public API, whereas option 1 involves changing a single keyword and shouldn't break anything, so option 1 seems like the obvious way to resolve this.
I'm happy to make this change and test it, if you're willing to accept a PR for this?
I think it's fine to just change it to public
Tasks:
Excellent, I'll send a PR for this, thanks for being decisive!
Sorry, I did it myself so I can release this now too :)
Even better :)
I'll test the new Nuget package with Lamar on Monday!
Have confirmed this fix allows NSwag to work with Lamar