I'm implementing email sending module and need to build URLs. My intention was to use IUrlHelper, but I really struggle to build this object due to the enormous amount of dependencies it needs to provide.
At the current moment I'm at this step:
ActionContext actionCtx = new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor());
_urlHelper = new UrlHelper(actionCtx);
but constructed that way urlHelper
still fails with an exception when trying to build URL.
Exception is:
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) at System.Collections.Generic.List`1.get_Item(Int32 index) at Microsoft.AspNetCore.Mvc.Routing.UrlHelper.get_Router()
So probably now it's required to create and set IRouter
instance, but as I could see it's again required to set tons of deps
So how this should be done correctly?