internal static object CreateContextualInstance(Type type, CodeFirstRegistration registration, out Dictionary <PropertyInfo, CodeFirstLazyInitialiser> dict, CodeFirstModelContext parentContext = null, bool useProxy = true) { if (CodeFirstManager.Current.Features.UseLazyLoadingProxies && useProxy) { dict = new Dictionary <PropertyInfo, CodeFirstLazyInitialiser>(); var proxy = _generator.CreateClassProxy(type, _opts, new CodeFirstProxyInterceptor(dict)); MoveNextContext(proxy, registration, parentContext); return(proxy); } else { dict = null; var instance = Activator.CreateInstance(type); MoveNextContext(instance, registration, parentContext); return(instance); } }
internal static void MoveNextContext(object instance, CodeFirstRegistration registration, CodeFirstModelContext parentContext = null) { if (ContextContainer.Current == null || ContextContainer.Current.Dictionary == null) { return; } else if (!ContextContainer.Current.Dictionary.ContainsKey(instance)) { if (registration is ContentTypeRegistration) { var newContext = new CodeFirstModelContext() { ContentType = (registration as ContentTypeRegistration), ParentContext = parentContext == null ? parentContext : _currentFrame }; if (_currentFrame != null) { _stack.Push(_currentFrame); } _currentFrame = newContext; ContextContainer.Current.Dictionary.Add(instance, _currentFrame); } else if (registration is TabRegistration) { var newContext = _currentFrame.Clone(); newContext.CurrentTab = registration as TabRegistration; _currentFrame = newContext; ContextContainer.Current.Dictionary.Add(instance, _currentFrame); } else if (registration is PropertyRegistration) { var newContext = _currentFrame.Clone(); newContext.CurrentProperty = registration as PropertyRegistration; _currentFrame = newContext; ContextContainer.Current.Dictionary.Add(instance, _currentFrame); } else { throw new InvalidOperationException("Unknown context registration type"); } } }