SystemLibrary.Common.Web
Classes
ActionContextInstance
An implementation of the 'old' thread safe singleton ActionContext we all know and love from .NET Framework
Cache
Caching for web applications
Default duration is 180 seconds
- configurable in appSettings.json or per Get() invocation
Auto-generates a cachekey for you if you don't specify one
- the flag "IsAuthenticated" is added to the cache key so it varies based on either logged in or logged out
- if IsAuthenticated is true and user's identity is of type "ClaimsPrincipal", it adds all roles to the cache key
Optionally, you can skip cache by setting parameters:
- skipForAuthenticatedUsers, false by default
- skipForAdmins, true by default
- true if current principal is in either of these case sensitive roles: "Admin", "Admins", "Administrator", "Administrators", "WebAdmins", "CmsAdmins"
- skipFor, your own implementation which returns true to skip
The Callee Cancelled Request Exception is thrown when the callee (you) cancel's the request.
- To cancel a request you must pass a 'Cancellation Token', and then cancel the request through the Cancellation Token
ClientResponse<T>
The main response class that all http requests in the HttpBaseClient returns
HtmlHelperFactory
HtmlHelperFactory builds a new instance of a HtmlBuilder outside of your View Context
HttpBaseClient
HttpBaseClient is a class for all http(s) requests in your project
- Note: Polly (nuget package) does a similar thing about Retry, and it does a few other things, but last time I checked; it does not reuse the TCP connection, so it is actually unusable)
Has:
a retry handler configured through constructor
if request fails and retry is True, the retry request uses a new tcp connection with 10 seconds timeout
a retry request occurs only for GET, HEAD or OPTION request methods, never for PUT/POST/DELETE
a timeout handler configurable through constructor, but also per method
each underlying tcp connection is cached for up to 2 minutes
Use HttpBaseClient directly or inherit from it, see the examples
Configurations: "systemLibraryCommonWeb": { "httpBaseClient": { "timeoutMilliseconds": 60000, "retryRequestTimeoutSeconds": 10, "cacheClientConnectionSeconds": 120 } }
HttpContextInstance
An implementation of the 'old' thread safe singleton HttpContext we all know and love from .NET Framework
A retry request exception is thrown if:
- "retryOnceOnRequestCancelled" is set to True, and if both the normal request and the retry request errors, this exception is thrown to the callee (you)
- a retry request exception can only occur on GET, HEAD or OPTION requests
If retryOnceOnRequestCancelled is False or if request method is POST, PUT or DELETE, this exception will never occur for the callee (you)
Note: A retry request gets a fixed timeout of 10 seconds to finish the request
Services
Dependency injection registry
look at it as 'Service Locator'
works in unit tests, console app's and web applications
Usage:
- requires a call in startup/program to 'services.AddCommonWebServices()' before usage
Interfaces
ILogWriter
ILogWriter is responsible for storing log messages
- Create a new class that implements ILogWriter
- Register your class as singleton implementation of the ILogWriter
Enums
An enum of various media types that can be sent to the HttpBaseClient request methods
The 'MediaType' is sent as an 'Accept' HEADER in the request
NOTE: Not all of them have been implemented yet though, but all will be sent as 'ACCEPT' header if specified, if you specify MediaType.none, no accept header is sent