-
Notifications
You must be signed in to change notification settings - Fork 3
ScopeProperties
ScopeProperties is a class that is used to transmit request-scoped data to repos and API clients. For example, ScopeProperties can transmit the user name associated with a request to a repo. As another example, ScopeProperties can transmit request headers to API clients using ScopeProperties.
ScopeProperties exposes two public properties.
| Property | Description |
|---|---|
public string User { get; set; } |
The user name associated with the request |
public Dictionary<string, object> OtherProperties { get; set; } |
A container for other request-scoped data |
Microsoft does provide an alternative means of transmitting request-scoped data to custom components -- namely, IHttpContextAccessor. The developer can setup IHttpContextAccessor for injection into a custom component by using the AddHttpContextAccessor IServiceCollection extension method IHttpContextAccessor. The HttpContext provides an Items property that can be used to attach any data to the request.
Although IHttpContextAccessor works just fine in many scenarios, to use it, your library has to include a dependency on Microsoft.AspNetCore.Http, which may be fine for API clients, but may not be desireable for repo classes. Also, in order to unit test classes that inject IHttpContextAccessor, you would have to resort to using something like Moq to mock the injected IHttpContextAccessor object. Because ScopeProperties is a simple POCO class, it has no additional dependencies and it does not require a mocking framework to mock an injected object.
Development Support
- Temporal Entities
- Base Repository Classes
- Base API Controller Classes
- ApiClient and SecureApiClient
- Security Utilities
- IServiceCollection Extension Methods
- HttpClient Extension Methods
- ScopeProperties
- MigrationsExtensionsDbContextDesignTimeFactory
Testing Support
- API Launcher
- Testing Strategy and Infrastructure
- Xunit Support Classes
- Testing Security Utilities
Related Projects