Establishing Workspace Context
When you create or open a repository instance, the repository engine returns a reference to the repository 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 navigate 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:
- From the root object, you can materialize the Workspaces collection and then retrieve a particular workspace from the resulting collection.
- You can invoke the get_Object method to explicitly retrieve a reference to the workspace object in whose context you want to operate.
- From the workspace definition object you can use the ObjectInstances method to establish a collection of all workspaces in the repository. You can then retrieve a particular workspace from that collection.
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. The Workspace class implements IRepository2, making methods like get_Object and get_RootObject equally available to a repository instance and the workspaces it contains.
To navigate to an object within the context of a workspace, start by invoking the get_RootObject method exposed by the workspace object, then navigate to other objects that are related to the root.
Important differences exist between workspaces and repository instances. For more information about how these differences affect programming within a workspace context, see Workspaces and Repository Instances.