autofac/Examples

Injecting a controller as a dependency

Closed this issue · 1 comments

Brief explanation of why I need to do this.
We're generating PDFs from HTML, and we need to render Razor views to do so. After much exploration, I came across several documents that say it's impossible without an actual controller. There is, however, two standalone Razor view libraries, however, they're both abandoned, and the latest one has an outstanding issue that prevents testing. Because of that, to test the service, we had to create a new MVC project. We just called it PdfTest and hope that it's a one off. But that doesn't fix the problem of dependencies in the actual MVC project now that we need to inject controllers.

Our constructor looks like

public PdfService(ControllerBase controller, string viewPath)

I'm not really sure what you're asking for, but if it's a "How do I do XYZ?" sort of question, please ask it on StackOverflow and tag it with autofac along with other relevant tags (e.g., aspnet-core or whatever). Many people monitor StackOverflow including the project owners here; but no one other than the two project owners look at question issues... so you likely won't get an answer for a very long time.