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

Consider adding services.AddHttpContextAccessor() to AddAspNetCore() #4487

Open
ossendorf-at-hoelscher opened this issue Feb 14, 2025 · 4 comments

Comments

@ossendorf-at-hoelscher
Copy link

Is your feature request related to a problem? Please describe.
I'm in the process of setting up a proof of concept solution where I need a minimum asp.net core application just to have an actual endpoint over the wire. But adding Csla to the services is not "just" calling AddCsla(o => o.AddAspNetCore()) but to also call AddHttpContextAccessor().

Describe the solution you'd like
AddAspNetCore() should internally call AddHttpContextAccessor() because it's required in that scenario anyways.
This would reduce the barrier on setting up a server. I had to check the samples to see how to correctly setup a server.

@rockfordlhotka
Copy link
Member

I thought about that too, but was concerned that this might be an anti-pattern - for a library to start bringing in services from other sources in ways that aren't under control of the developer.

For example, some of our unit tests provide a mock accessor because the real one isn't available or valid.

@StefanOssendorf
Copy link
Contributor

StefanOssendorf commented Feb 15, 2025

I don't think that's an anti pattern. If we start using the options system we have to include that system in our di to get it even working. And adding something is not a problem. Last registration wins and is the default for di. So there are no problems as long as a user registers it's own implementation afterwards. And that is currently common in the ecosystem.

@rockfordlhotka
Copy link
Member

My only other thought is that it could get registered twice, which wouldn't cause a functional difference. I suppose that's not a blocker.

@StefanOssendorf
Copy link
Contributor

It's not added twice. Most of all framework dependencies are added with Try.
https://github.com/dotnet/aspnetcore/blob/ec389c71560ceba39148831343ba8f20962e0228/src/Http/Http/src/HttpServiceCollectionExtensions.cs#L23

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

No branches or pull requests

3 participants