@@ -22,16 +22,23 @@ public class JsonApiFormatter : JsonMediaTypeFormatter
2222 public JsonApiFormatter ( )
2323 : this ( new ErrorSerializer ( ) )
2424 {
25+ if ( _modelManager == null ) _modelManager = new ModelManager ( ) ;
26+ SupportedMediaTypes . Add ( new MediaTypeHeaderValue ( "application/vnd.api+json" ) ) ;
2527 }
2628
2729 internal JsonApiFormatter ( IErrorSerializer errorSerializer )
2830 {
2931 _errorSerializer = errorSerializer ;
30- SupportedMediaTypes . Add ( new MediaTypeHeaderValue ( "application/vnd.api+json" ) ) ;
3132 }
3233
33- public IPluralizationService PluralizationService { get ; set ; }
34+ public JsonApiFormatter ( IModelManager modelManager ) : this ( )
35+ {
36+ _modelManager = modelManager ;
37+ }
38+
39+ public IPluralizationService PluralizationService { get ; set ; } //FIXME: Deprecated, will be removed shortly
3440 private readonly IErrorSerializer _errorSerializer ;
41+ private readonly IModelManager _modelManager ;
3542
3643 private Lazy < Dictionary < Stream , RelationAggregator > > _relationAggregators
3744 = new Lazy < Dictionary < Stream , RelationAggregator > > (
@@ -152,7 +159,7 @@ protected void Serialize(object value, Stream writeStream, JsonWriter writer, Js
152159
153160 // Do the Id now...
154161 writer . WritePropertyName ( "id" ) ;
155- var idProp = GetIdProperty ( value . GetType ( ) ) ;
162+ var idProp = _modelManager . GetIdProperty ( value . GetType ( ) ) ;
156163 writer . WriteValue ( GetValueForIdProperty ( idProp , value ) ) ;
157164
158165 PropertyInfo [ ] props = value . GetType ( ) . GetProperties ( ) ;
@@ -819,15 +826,17 @@ protected object GetById(Type type, string id)
819826 {
820827 // Only good for creating dummy relationship objects...
821828 object retval = Activator . CreateInstance ( type ) ;
822- PropertyInfo idprop = GetIdProperty ( type ) ;
829+ PropertyInfo idprop = _modelManager . GetIdProperty ( type ) ;
823830 idprop . SetValue ( retval , System . Convert . ChangeType ( id , idprop . PropertyType ) ) ;
824831 return retval ;
825832 }
826833
834+ /*
827835 protected PropertyInfo GetIdProperty(Type type)
828836 {
829837 return type.GetProperty("Id");
830838 }
839+ */
831840
832841 protected string GetValueForIdProperty ( PropertyInfo idprop , object obj )
833842 {
@@ -846,7 +855,7 @@ protected string GetValueForIdProperty(PropertyInfo idprop, object obj)
846855 protected string GetIdFor ( object obj )
847856 {
848857 Type type = obj . GetType ( ) ;
849- PropertyInfo idprop = GetIdProperty ( type ) ;
858+ PropertyInfo idprop = _modelManager . GetIdProperty ( type ) ;
850859 return GetValueForIdProperty ( idprop , obj ) ;
851860 }
852861
0 commit comments