I'm trying to create a logger that will write the queries LINQ executes to the page formatted with the great javascript library SyntaxHighlighter.
For that, I've set the DataContext's Log property to my custom logger, which is working well.
Now I just need to get the current Controller object (outside the controller execution context) so I can set some ViewData with what needs to be outputted.
Any suggestions?
If you want to perform operations outside of the controller, then action-filters (etc) are a good bet; just inherit from ActionFilterAttribute, override OnActionExecuting (etc) to inject data into the view, and mark your controller with [YourCustomFilter].
Like this
(original; I may have misunderstood)
It would be better to use dependency injection here, by passing the log-writer into the repository as a constructor argument (ideally via something like StructureMap, which works very well with MVC via StructureMapControllerFactory, or similar).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With