Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When do we need to use System.AppContext?

Tags:

c#

Seems AppContext only has a property called BaseDirectory. But Environment class seems to have much more properties and methods.

So is AppContext being replaced by Environment class now?

like image 331
vik santata Avatar asked Jul 01 '15 03:07

vik santata


People also ask

What is AppContext C#?

The AppContext class enables library writers to provide a uniform opt-out mechanism for new functionality for their users. It establishes a loosely coupled contract between components in order to communicate an opt-out request. This capability is typically important when a change is made to existing functionality.

What is an App context?

The application context keeps track of the application-level data during a request, CLI command, or other activity. Rather than passing the application around to each function, the current_app and g proxies are accessed instead.


1 Answers

AppContext has been introduced with .NET 4.6 thus it won't be replaced.

MSDN says:

AppContext is a new compatibility feature that enables library writers to provide a uniform opt-out mechanism for new functionality for their users. It established a loosley-coupled contract between components in order to communicate an opt-out request. This capability is typically important when a change is made to existing functionality. Conversely, there is already an implicit opt-in for new functionality.

With AppContext, libraries define and expose compatibility switches, while code that depends on them can set those switches, to affect the library behavior. By default libraries provide the new functionality and only alter it (e.g. provide the old behavior) if the switch is set.

In summary, it provides functionality to deal with multiple versions of the same dll.

Code example is within the provided link.

like image 64
Andy Avatar answered Oct 17 '22 01:10

Andy