/// <inheritdoc />
        public IResourceGraphBuilder AddResource(Type entityType, Type idType, string pluralizedTypeName = null)
        {
            AssertEntityIsNotAlreadyDefined(entityType);

            pluralizedTypeName = pluralizedTypeName ?? _resourceNameFormatter.FormatResourceName(entityType);

            _entities.Add(GetEntity(pluralizedTypeName, entityType, idType));

            return(this);
        }
 /// <summary>
 /// Derives a template from the resource type, and checks if this template was already registered.
 /// </summary>
 private string TemplateFromResource(ControllerModel model)
 {
     if (_registeredResources.TryGetValue(model.ControllerName, out Type resourceType))
     {
         var template = $"{_namespace}/{_formatter.FormatResourceName(resourceType)}";
         if (_registeredTemplates.Add(template))
         {
             return(template);
         }
     }
     return(null);
 }
Beispiel #3
0
        private string GetResourceNameFromDbSetProperty(PropertyInfo property, Type resourceType)
        {
            // this check is actually duplicated in the DefaultResourceNameFormatter
            // however, we perform it here so that we allow class attributes to be prioritized over
            // the DbSet attribute. Eventually, the DbSet attribute should be deprecated.
            //
            // check the class definition first
            // [Resource("models"] public class Model : Identifiable { /* ... */ }
            if (resourceType.GetCustomAttribute(typeof(ResourceAttribute)) is ResourceAttribute classResourceAttribute)
            {
                return(classResourceAttribute.ResourceName);
            }

            // check the DbContext member next
            // [Resource("models")] public DbSet<Model> Models { get; set; }
            if (property.GetCustomAttribute(typeof(ResourceAttribute)) is ResourceAttribute resourceAttribute)
            {
                return(resourceAttribute.ResourceName);
            }

            // fallback to dsherized...this should actually check for a custom IResourceNameFormatter
            return(_resourceNameFormatter.FormatResourceName(resourceType));
        }
 private string FormatResourceName(Type resourceType, IResourceNameFormatter resourceNameFormatter)
 {
     resourceNameFormatter = resourceNameFormatter ?? new DefaultResourceNameFormatter();
     return(resourceNameFormatter.FormatResourceName(resourceType));
 }