@@ -174,20 +174,27 @@ public IContextGraphBuilder AddDbContext<T>() where T : DbContext
174174 var ( isJsonApiResource , idType ) = GetIdType ( entityType ) ;
175175
176176 if ( isJsonApiResource )
177- _entities . Add ( GetEntity ( GetResourceName ( property ) , entityType , idType ) ) ;
177+ _entities . Add ( GetEntity ( GetResourceName ( property , entityType ) , entityType , idType ) ) ;
178178 }
179179 }
180180
181181 return this ;
182182 }
183183
184- private string GetResourceName ( PropertyInfo property )
184+ private string GetResourceName ( PropertyInfo property , Type resourceType )
185185 {
186- var resourceAttribute = property . GetCustomAttribute ( typeof ( ResourceAttribute ) ) ;
187- if ( resourceAttribute == null )
188- return property . Name . Dasherize ( ) ;
189-
190- return ( ( ResourceAttribute ) resourceAttribute ) . ResourceName ;
186+ // check the class definition first
187+ // [Resource("models"] public class Model : Identifiable { /* ... */ }
188+ if ( resourceType . GetCustomAttribute ( typeof ( ResourceAttribute ) ) is ResourceAttribute classResourceAttribute )
189+ return classResourceAttribute . ResourceName ;
190+
191+ // check the DbContext member next
192+ // [Resource("models")] public DbSet<Model> Models { get; set; }
193+ if ( property . GetCustomAttribute ( typeof ( ResourceAttribute ) ) is ResourceAttribute resourceAttribute )
194+ return resourceAttribute . ResourceName ;
195+
196+ // fallback to dsherized...this should actually check for a custom IResourceNameFormatter
197+ return property . Name . Dasherize ( ) ;
191198 }
192199
193200 private ( bool isJsonApiResource , Type idType ) GetIdType ( Type resourceType )
0 commit comments