Establishing Workspace Context

When you create or open a Repository instance, the Repository returns to you a reference to the Repository's root object. From there, you can immediately begin to manipulate other Repository objects. For example, you can invoke get_Object to materialize a reference to a specific Repository object. Or you can begin to move from the root object to other Repository objects. In either of these cases, the resulting references refer to run-time objects that exist within the general context of the open Repository instance. Thus, if you invoke methods exposed by this object, the methods perform their work within that context.

On the other hand, you can first establish a workspace context before manipulating any Repository objects. To establish a workspace context, you must materialize a workspace object in any of these ways:

After you have a reference to the workspace object, you can operate within the context of that workspace. To retrieve an object directly within the context of the workspace, you can invoke the get_Object method as exposed by the workspace object. (Remember that the Workspace class implements IRepository2, so each workspace exposes methods like get_Object and get_RootObject.) Similarly, to move to an object within the context of a workspace, start by invoking the get_RootObject method exposed by the workspace object. Then, move from the root object to other objects.

To reiterate: Remember that the Workspace class and the Repository class both implement the IRepository2 interface. Thus, you can invoke methods like get_Object and get_RootObject either from a Repository or from a workspace. When you invoke one of these methods, the resulting object reference uses the same context as the object on which you called the method. Thus, if you invoke get_Object from a Repository, the resulting object exists within the general context of the open Repository instance, and subsequent calls to that new object's methods will occur within the general context of the open Repository instance. But if you invoke get_Object from a workspace, the resulting object exists within the specific context of that workspace, and subsequent calls to that new object's methods will occur within the specific context of that workspace.