@@ -174,20 +174,27 @@ public IContextGraphBuilder AddDbContext<T>() where T : DbContext
174
174
var ( isJsonApiResource , idType ) = GetIdType ( entityType ) ;
175
175
176
176
if ( isJsonApiResource )
177
- _entities . Add ( GetEntity ( GetResourceName ( property ) , entityType , idType ) ) ;
177
+ _entities . Add ( GetEntity ( GetResourceName ( property , entityType ) , entityType , idType ) ) ;
178
178
}
179
179
}
180
180
181
181
return this ;
182
182
}
183
183
184
- private string GetResourceName ( PropertyInfo property )
184
+ private string GetResourceName ( PropertyInfo property , Type resourceType )
185
185
{
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 ( ) ;
191
198
}
192
199
193
200
private ( bool isJsonApiResource , Type idType ) GetIdType ( Type resourceType )
0 commit comments