In.. net, the context concept runs through. net. it provides services and content similar to the running environment. in. in. net, context-based interception technology has been very obscure, and there are not many documents to explain. However, context-based interception technology provides very powerful functions. So that we can easily implement a programming mode similar to AOP .. Net3.0 uses context interception technology in most cases.
In. in. net, the common particles of component services are domain and context ). among them, the services provided in the domain are generally only 'synchronous region '. of course ,. net also provides many COM + services, but the components (classes) of the services must be directly or indirectly inherited fromThe COM + service provided by servicedcomponent (the component to be served). Net is all in the namespace System. enterpriseservices In which services such as message queue, instant activation, Object pool... are provided.
When developing with. net, we all know that we use any language supported by. net. Code All are managed code. the so-called managed code generation il language can only run in CLR. and enjoy the garbage collection provided by CLR, hosting heap... and so on. however, when Windows provides a process for our il operation, it does not know the so-called managed environment. Windows only provides processes, and there is no concept of a managed environment in the process. the domain serves as a bridge between Windows processes and Il. In a Windows process, all domains share the resources that CLR provides, such as garbage collection, managed heap, and JIT, loading, and uninstalling. Program Set. That is to say, all our il code must run in the domain. Of course, when we start. net Program, a default domain will be created to load and run our. and provides a managed heap. You can also create a new domain. Therefore, each Windows process can host multiple domains. In. net, objects cannot be directly referenced across domains. Each. Net object is created as a hosted heap of the domain to which it belongs. The cross-origin access of an object must use a proxy, and the object can be blocked (directly or indirectly inherited from financialbyrefobject). The cross-origin access object is called remote access ).
In. net, the domain granularity is still very large. If we do not explicitly create a new domain, all the components (classes) in our program usually run in the same domain. In. net, context provides a runtime environment with a smaller granularity than the domain. A domain can have multiple contexts, but one context can belong to only one domain.
Like the domain, our. the. NET Component (class) must also run in different contexts, but different contexts provide different context services. Each domain also has a default context, the default context does not provide any services. The biggest advantage of context is that we can use context interception technology to provide custom services for the components (classes) hosted in the context. In this way, we can implement the so-called AOP programming. We can add the so-called pipeline work in AOP as a service to the fixed service below, so that every call to the component (class) in this context will be intercepted, then add the Service (pipeline method) to the component (class). It is like weaving the Service (pipeline method) into the (AOP term) to the component (class.