Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does Context mean?

Tags:

.net

This word never makes sense to me. I wouldn't understand ussualy why Database Access Objects are named with this naming convention and also i have seen many times this word used in others codes which wasn't about Database objects.

Can someone explain mean of this word in programming to someone who is not english and can give some examples about general usage in programming area ?

like image 686
Freshblood Avatar asked Feb 06 '11 19:02

Freshblood


People also ask

What does context mean example?

The definition of context is the words that surround other words and impact their meaning or the setting in which something occurs. An example of context is the words that surround the word "read" that help the reader determine the tense of the word.

What does context mean simple?

Definition of context 1 : the parts of a discourse that surround a word or passage and can throw light on its meaning. 2 : the interrelated conditions in which something exists or occurs : environment, setting the historical context of the war.

What is context mean in writing?

Context is information that helps the message of a literary text make sense. Whether it's a novel, a memoir, or a collection of short stories, a piece of writing can be interpreted variably depending on the contextual factors you provide as the author.

What is context of a sentence?

The context of a word, sentence, or text consists of the words, sentences, or text before and after it which help to make its meaning clear. Without a context, I would have assumed it was written by a man. 3.

What does giving something context mean?

Providing context (for context) is giving additional information that will help to make sense of something. For example - quoting someone out of context. A more accurate phrase to have used would have been "for perspective" or "to put that into perspective".


2 Answers

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.

like image 54
Erik Funkenbusch Avatar answered Oct 04 '22 17:10

Erik Funkenbusch


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)

like image 44
Kamyar Avatar answered Oct 04 '22 17:10

Kamyar