It depends entirely on the scope within these components are used and their dependencies, to elaborate:
Logger
A logger is usually alive throughout the entire lifespan of the application and can be used all over the application (scope), the logger doesn't care for the request
or the controller
(dependencies). Best Lifetime Scope: Application.
LogSource / LogContext
Unlike logger, LogSource / LogContext are contextual object that are to be used withing a given context (scope), these object are aware of their context (controller
/ request
) (dependencies). Best Lifetime Scope: Controller / Request.
Localizer
Localizer is a bit less clear-cut as the other components. For one it is use application wide (Controllers, Views etc.) (scope). But as for its dependencies the matter is implementation specific, your localizer
may need a CultureInfo
object for construction or it may not. In a case when it is not required then there are no dependencies for that component and an Application scope will fit.
On the other hand if a culture is required then it is a dependency for that component. Now it's logical to then scope it to a user session but this is where the idea of performance and dependency specifics comes to play. If you scope the localizer
to a user session then each user will have x
amount of time the server to read the localization file before it's served its response. Additionally the dependency is not the user session
but the user's culture
, whilst the possible user session
s are infinite, the possible supported locals are all but infinite. Keeping that in mind you can then create a localization pool
that contains every supported local (and possibly a fallback local for the ones that aren't supported),scoped to the application, which can serve localizers
scoped to user sessions
.
To sum up - You can apply the scope-dependencies logic to any component but as we've seed with the localizer
it's always best to understand the component and the implication of scoping that component to a specific scope.