Page MenuHomePhabricator

Enable `RequestContext` to be created via a factory method & inject other service objects into it
Open, Needs TriagePublic

Description

A quick search (https://codesearch.wmcloud.org/search/?q=new%20RequestContext&i=nope&files=&excludeFiles=&repos=) in our code base shows new RequestContext() in some places (apart from tests) and the classes that make use of the request context has a lot of services objects available.

I'm wondering if we would like to inject these service objects into the request, create request context objects via a factory method or make it a service? It would really help in DI on this class and also loosely couple it with other classes and also make writing tests easier with other classes.

Not sure which tags to use so please feel free to edit.

Event Timeline

xSavitar renamed this task from Make `RequestContext` a service and create it via a factory method to Enable `RequestContext` to be created via a factory method.May 2 2022, 9:29 PM
xSavitar renamed this task from Enable `RequestContext` to be created via a factory method to Enable `RequestContext` to be created via a factory method & inject other service objects into it.
xSavitar updated the task description. (Show Details)
Tgr subscribed.

RequestContext includes lots of different things (configuration, the actual request context, the user, the response etc) which probably have no business being in the same service.

RequestContext includes lots of different things (configuration, the actual request context, the user, the response etc) which probably have no business being in the same service.

+1, I think the eventual goal is to get rid of RequestContext, or at least remove most of its dependencies (language, user, title, etc.). Honestly, I don't think it's worth spending even a single minute trying to make that class more usable. That time could probably be better spent trying to replace RequestContext with something more appropriate.