DefaultRequestContext class
namespace: Serenity.Services assembly: Serenity.Net.Services
Default implementation for a IRequestContext.
public class DefaultRequestContext : IHasHandlerSettings, IRequestContext, IServiceProviderAccessor
| parameter | description |
|---|---|
| behaviors | Behavior provider |
| cache | Two level cache |
| localizer | Text localizer |
| permissions | Permissions |
| userAccessor | User access |
| handlerSettings | Request handler settings |
| serviceProviderAccessor | Gives the services of the current request, which the context gives as its ServiceProvider, e.g. for the validation rules a save handler checks. |
Public Members
| name | description |
|---|---|
| DefaultRequestContext(…) | Default implementation for a IRequestContext. |
| Behaviors { get; } | |
| Cache { get; } | |
| HandlerSettings { get; } | |
| Localizer { get; } | |
| Permissions { get; } | |
| ServiceProvider { get; } | Gets the services of the current request, which are looked up on each call, as the context is a singleton, or none when it is not given the IServiceProviderAccessor. |
| User { get; } |
Exceptions
| exception | condition |
|---|---|
| ArgumentNullException | Any of the required arguments is null. |
Remarks
This implementation is registered as a singleton by default, so it assumes its dependencies (e.g. IUserAccessor, IPermissionService, ITextLocalizer) are also registered as singletons. The default IUserAccessor implementation in web applications reads the current user from the ambient HTTP context, so a singleton is safe in that case.
If you need scoped implementations of any of these dependencies, register your own IRequestContext implementation and resolve them on demand from ServiceProvider (which returns the current request's scoped provider in web applications, and the root provider otherwise) instead of capturing them in the constructor.
See Also
- interface IHasHandlerSettings
- interface IRequestContext
- interface IServiceProviderAccessor
- Source: DefaultRequestContext.cs