Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inject HttpRequest #32

Open
tomfaltesek opened this issue Feb 7, 2019 · 5 comments
Open

Inject HttpRequest #32

tomfaltesek opened this issue Feb 7, 2019 · 5 comments

Comments

@tomfaltesek
Copy link

I have services that depend on IHttpContextAccessor so that certain HTTP Headers and claim data can be accessed. Is there any way to configure DI for some form of the current HttpRequest?

@ranouf
Copy link

ranouf commented Feb 7, 2019

What I use is:

        public IServiceProvider Build()
        {
            services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
        }

But currently, Startup seems to be not invoked with .net core 2.2 ...

@tomfaltesek
Copy link
Author

What I use is:

        public IServiceProvider Build()
        {
            services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
        }

But currently, Startup seems to be not invoked with .net core 2.2 ...

Yeah, that works great for a regular dotnet core web project. It does not work for Azure Functions. The HttpContext property is always null. Perhaps I'm doing something incorrectly.

@DonFrazier-zz
Copy link

Did you include an [assembly: FunctionsStartup(typeof(MyStartupClass))] attribute somewhere in your function?

@nickwinger
Copy link

i also would like to be able to inject the httpRequest into a service, e.g. token validation etc.

@nickwinger
Copy link

nickwinger commented Dec 18, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants