Chili.Opf3 Send comments on this topic.
Factory Property
See Also  Example
Chili.Opf3 Namespace > ObjectContext Class : Factory Property




Gets the ObjectContextFactory that allows creating ObjectContext instances by applying a policy. Such as creating a new ObjectContext instance on each call (ASP.NET applications) or for each different thread (Windows applications).

Syntax

Visual Basic (Declaration) 
Public Shared ReadOnly Property Factory As ObjectContextFactory
Visual Basic (Usage)Copy Code
Dim value As ObjectContextFactory
 
value = ObjectContext.Factory
C# 
public static ObjectContextFactory Factory {get;}
Managed Extensions for C++ 
public: __property static ObjectContextFactory* get_Factory();
C++/CLI 
public:
static property ObjectContextFactory^ Factory {
   ObjectContextFactory^ get();
}

Example

This example shows how to set up the factory to create an ObjectContext instance for each new thread.
C#Copy Code
// Set the policy for multi threading. 
ObjectContext.Factory.Policy = new PerThreadObjectContextFactoryPolicy(delegate() 

    MsSqlStorage storage = new MsSqlStorage("... connection string ..."); 
    ObjectContext ctx = new ObjectContext(storage); 
 
    return ctx; 
}); 
 
// ... Other code 
 
// Have an ObjectContext instance created 
ObjectContext context = ObjectContext.Factory.GetObjectContext();

Requirements

Platforms: Windows 2000, Windows XP family, Windows Server 2003 family, Windows Vista family

See Also