Suite Context¶
On modular applications there is usually a need to store and access contextual
information. An example of this is the HttpContext provided by Asp.Net. A
similar approach is use by the Suite framework, which provides a ISuiteContext
service through DI.
Important
Below we show how to retrieve and store information from and into the ISuiteContext directly, but we strongly recommend implementing extension methods to encapsulate this logic and avoid using the methods shown below directly all over a module. See this.
Accessing the SuiteContext¶
The ISuiteContext can be accessed by injecting it as a dependency. For example:
C# | |
---|---|
Retrieving information from ISuiteContext¶
The ISuiteContext
interface provides two methods to retrieve information,
Get
and GetRequired
. Both methods accept a string key, and if there is a
value for the key, both methods have the same behavior, returning the value.
These methods differ when the value for the key is not present, in that case
Get
will return null
while GetRequired
will throw an exception.
C# | |
---|---|
Storing information on the ISuiteContext¶
The Set
method is used to store information on the ISuiteContext. To do so we
need to pass the string key and the object to be stored.
C# | |
---|---|