Skip to content

Conversation

hishamco
Copy link
Member

@hishamco hishamco commented Jul 1, 2025

This will allow us to access the ClaimsPrincipal in the drivers, which will simplify the user access from there.

Fixes #1058

@gvkries
Copy link
Contributor

gvkries commented Jul 1, 2025

I'm a bit concerned about the impact of this change. It introduces overhead to all requests, even though only a small subset of drivers actually require access to the HTTP context. For example, public content which typically doesn't need user-specific data will now always access the IHttpContextAccessor and its AsyncLocal storage, even when the user isn't needed. This could have performance implications and might be worth reconsidering.

@hishamco
Copy link
Member Author

hishamco commented Jul 1, 2025

I remember this had been suggested long time ago, I need to find the related issue

@gvkries
Copy link
Contributor

gvkries commented Jul 1, 2025

After reconsidering, I think adding the HTTP context to IBuildShapeContext might actually be beneficial. While it does introduce some overhead, it could help reduce reliance on IHttpContextAccessor in other parts of the codebase, potentially improving performance overall. Even though all requests will now touch the context, having it readily available might simplify access patterns and reduce redundant lookups.

@gvkries
Copy link
Contributor

gvkries commented Jul 1, 2025

Do you mean this #1058?

@hishamco
Copy link
Member Author

hishamco commented Jul 1, 2025

Exactly

{
_handlers = handlers;
_contentDefinitionManager = contentDefinitionManager;
_shapeFactory = shapeFactory;
_layoutAccessor = layoutAccessor;
_logger = logger;
_httpContext = httpContextAccessor.HttpContext;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure this can be done in the constructor, once? Is DefaultContentDefinitionDisplayManager really scoped?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it's

services.AddScoped<IContentDefinitionDisplayManager, DefaultContentDefinitionDisplayManager>();

@hishamco hishamco requested a review from sebastienros July 3, 2025 17:28
@gvkries
Copy link
Contributor

gvkries commented Jul 18, 2025

I think this is worth being taken. But I would suggest to also include some usage examples, even if it makes the PR bigger. That can show the benefit of the change.

@hishamco
Copy link
Member Author

This will be HUGE :) I never mind to do it if there's no objection

Copy link
Contributor

It seems that this pull request didn't really move for quite a while. Is this something you'd like to revisit any time soon or should we close? Please comment if you'd like to pick it up.

@github-actions github-actions bot added the stale label Sep 16, 2025
@sebastienros
Copy link
Member

This should need some actual usages of the new property.

@github-actions github-actions bot removed the stale label Sep 16, 2025
@hishamco
Copy link
Member Author

This should need some actual usages of the new property.

Sure

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

Successfully merging this pull request may close these issues.

Simplify access to the User object from within drivers
3 participants