Esempio n. 1
0
        private ModelMetadataRegistryItem CheckMetadataAndApplyConvetions([NotNull] Type modelType, ModelMetadataRegistryItem item)
        {
            if (conventions.Count == 0 || NoNeedToApplyConvetionsFor(modelType, item))
            {
                return(item);
            }

            lock (this)
            {
                if (NoNeedToApplyConvetionsFor(modelType, item))
                {
                    return(item);
                }

                ModelMetadataRegistryItem registeredItem;
                // ensure that conventions were not appied by another thread
                if (mappings.TryGetValue(modelType, out registeredItem) && registeredItem.IsConventionsApplied)
                {
                    return(registeredItem);
                }

                var context = new AcceptorContext(modelType, item != null);
                var canAcceptConventions = ConventionAcceptor.CanAcceptConventions(context);

                if (!canAcceptConventions)
                {
                    ProcessUnacceptedModelType(modelType, item);
                    return(item);
                }

                if (item == null)
                {
                    // try get existing (item can be created by another thread) or create new
                    item = GetOrCreate(modelType);
                }

                // ensure convenstion is not applied yet
                if (item.IsConventionsApplied)
                {
                    return(item);
                }

                ApplyMetadataConvenstions(modelType, item);
            }

            return(item);
        }
Esempio n. 2
0
 /// <summary>
 /// Checks whether metadata for class can be accepted
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 public virtual bool CanAcceptConventions([NotNull] AcceptorContext context)
 {
     return(context.HasMetadataConfiguration);
 }