I am implementing an email sending module and must create urls. My intention was to use IUrlHelper, but I'm really trying to build this object due to the huge number of dependencies that it needs to be provided.
I am currently at this step:
ActionContext actionCtx = new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor());
_urlHelper = new UrlHelper(actionCtx);
but constructed in this way urlHelperstill fails with an exception when trying to create a URL.
An exception:
The index was out of range. Must be non-negative and smaller than the size of the collection. Parameter name: index in System.ThrowHelper.ThrowArgumentOutOfRangeException (ExceptionArgument argument, ExceptionResource resource) in System.Collections.Generic.List`1.get_Item (Int32 index) in Microsoft.AspNetCore.Mvc.Routing.UrlHelper.get_Router ()
Now, probably, now it was required to create and install an instance IRouter, but, as I could see, it again required to install tons of deps
So how should this be done right?
source
share