/// <summary> /// Registers a context. Uses given ContextConfiguration. Accepts a context factory that is a delegate used for /// instantiating the context. This allows developers to instantiate context using a custom constructor. /// </summary> /// <param name="contextFactory"></param> /// <param name="configuration"></param> public void RegisterContext(Func <object> contextFactory, ContextConfiguration configuration) { object contextInstance = null; try { if (contextFactory == null) { throw new ArgumentNullException("contextFactory"); } contextInstance = contextFactory(); if (contextInstance == null) { throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, DynamicDataResources.MetaModel_ContextFactoryReturnsNull), "contextFactory"); } Type contextType = contextInstance.GetType(); if (!_schemaCreator.ValidDataContextType(contextType)) { throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, DynamicDataResources.MetaModel_ContextTypeNotSupported, contextType.FullName)); } } catch (Exception e) { s_registrationException = e; throw; } // create model abstraction RegisterContext(_schemaCreator.CreateDataModel(contextInstance, contextFactory), configuration); }