Exemplo n.º 1
0
        public ResourceConfigurationBuilder <TResource, TController> Resource <TResource, TController>()
        {
            var resource = typeof(TResource);

            if (!HasOnlyOneGetMethod <TController>())
            {
                throw new InvalidOperationException($"The controller being registered ({typeof(TController).FullName}) can only have one GET method with single id parameter for the resource type {typeof(TResource).FullName}.");
            }

            if (DoesModelHaveReservedWordsRecursive(resource))
            {
                throw new InvalidOperationException($"The resource being registered ({resource.FullName}) contains properties that are reserved words by JsonApi (Relationships, Links).");
            }

            if (!AssertModelHasIdProperty <TResource>())
            {
                throw new InvalidOperationException($"The resource being registered ({resource.FullName}) must contain an Id property. It can be of any value type.");
            }

            if (!ResourceConfigurationsByType.ContainsKey(resource))
            {
                var newResourceConfiguration = new ResourceConfigurationBuilder <TResource, TController>(this);
                ResourceConfigurationsByType[resource] = newResourceConfiguration;
                return(newResourceConfiguration);
            }
            else
            {
                return(ResourceConfigurationsByType[resource] as ResourceConfigurationBuilder <TResource, TController>);
            }
        }
Exemplo n.º 2
0
 public ResourceConfigurationBuilder <TResource> Resource <TResource>()
 {
     if (!ResourceConfigurationsByType.ContainsKey(typeof(TResource)))
     {
         var newResourceConfiguration = new ResourceConfigurationBuilder <TResource>(this)
         {
             ConfigurationBuilder = this
         };
         ResourceConfigurationsByType[typeof(TResource)] = newResourceConfiguration;
         return(newResourceConfiguration);
     }
     else
     {
         return(ResourceConfigurationsByType[typeof(TResource)] as ResourceConfigurationBuilder <TResource>);
     }
 }