aspnet/DependencyInjection

Accessing services from IViewComponentHelper extension methods

hejtmii opened this issue · 4 comments

Hi,

Not sure if this question is more relevant for DependencyInjection or other. Let me know if some other would be more suitable.

We would like to write a set of extension methods on interface IViewComponentHelper, so our customers could use the following code in view:

@await Component.OurComponent(someParameters)

We need to get instance of our service in that extension method, but IViewComponentHelper does not expose HttpContext so cannot get the service using DI best practices for custom code, we need to make a nasty workaround with static service accessor property or force customers to pass extra reference to IHtmlHelper as well (and we don't like it).

What would be the proper way how to access service in that case / could interface IViewComponentHelper be extended with the context?

IViewComponentHelper doesn't have anything to do with DependencyInjection. This sounds like an MVC-related request.

Thank you for quick response, and I apologize for placing it wrongly. Is there some easy way how to easily move this or should I just close this and create new in there?

This issue was moved to aspnet/Mvc#5438