What does Context mean?
in .NET AFAIK, We have Httpcontext in web and ObjectContext in Entity Framework. I'm not aware of any other use of context in .NET framework, but there may be more usages. So, here's a simple explanation about the two I know.
HttpContext:
Encapsulates all HTTP-specific information about an individual HTTP request. Properties of this class include the Request object, the Response object, the Session object, and an AllErrors property which keeps an array of Exception objects occured during the current request. It's simply a wrapper class.ObjectContext: Quoting from : https://github.com/geersch/EntityFrameworkObjectContext
every object returned by a query (Linq To Entities, Entities SQL…) is automatically attached to an object context. This context tracks the changes applied to these objects so that it can later figure out how to persist these changes to the underlying data store.
This object context is represented by a class fittingly named ObjectContext. The ObjectContext encapsulates a couple of things, namely:
- The connection to the underlying data store (database)
- Metadata describing the Entity Data Model (EDM)
- An ObjectStateManager for tracking changes to the objects
So, it seems like it is used basically when we want to manage some logically relative objects. Objects that we can put in one logical context. (e.g. entities in EF or Request/Response/Session/etc in HttpContext)
Something is typically called a "context" in computer programming when that something encapsulates some kind of state.
In the example of Linq 2 sql or EF, you have a Data Context, or Object Context.. these encapsulate the state of your data model, including connections and versioning.
In the case of HttpContext, it's encapsulating the state of an Http connection (which is normally considered stateless, but HttpContext tries to give state to it).
In english, if we refer to context, we refer to information surrounding something that allows you to understand the entire situation in which that something exists. For example, we may say a statement is "taken out of context". That would mean a statement by itself doesn't necessarily reveal all the information.
Out of context:
People are tasty.
In Context:
We should never say or think that people are tasty.
Without the "context", the statement has a different meaning. Programming has taken the term to similarly refer to the data surrounding something that gives it more meaning.