CarterCommunity / Carter

Carter is framework that is a thin layer of extension methods and functionality over ASP.NET Core allowing code to be more explicit and most importantly more enjoyable.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IHttpContextAccessor currently doesn't work

Dreamwalker666 opened this issue · comments

I discovered that I couldn't access the HttpContext in a DI based way. Not sure if this support was excluded for some reason (or I've completely gone about it the wrong way :)

I added the following before https://github.com/CarterCommunity/Carter/blob/master/src/Carter/CarterExtensions.cs#L86

                //  Setup HttpContext if services has been added with AddHttpContextAccessor
                var httpContext = (IHttpContextAccessor)ctx.RequestServices.GetService(typeof(IHttpContextAccessor));
                if (httpContext != null)
                {
                    httpContext.HttpContext = ctx;                    
                }

This solves my particular issue but would this be wanted in the main repo? If so I'll make a PR