Figured it out!
I had to replace this:
var factory = _dependencyResolver.GetService<Func<string, string, string, IContext>>();
IContext context = factory(contextToken, hostUrl, request.Url.Authority);
with this:
var context =
_dependencyResolver.RequestLifetimeScope.Resolve<IContext>(
new NamedParameter("contextToken", contextToken),
new NamedParameter("hostUrl", hostUrl),
new NamedParameter("appUrl", request.Url.Authority));