@@ -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 = ModelManager . Instance . GetIdProperty ( value . GetType ( ) ) ;
162+ var idProp = _modelManager . GetIdProperty ( value . GetType ( ) ) ;
156163 writer . WriteValue ( GetValueForIdProperty ( idProp , value ) ) ;
157164
158165 // Leverage the cached map to avoid another costly call to GetProperties()
@@ -799,7 +806,7 @@ protected object GetById(Type type, string id)
799806 {
800807 // Only good for creating dummy relationship objects...
801808 object retval = Activator . CreateInstance ( type ) ;
802- PropertyInfo idprop = ModelManager . Instance . GetIdProperty ( type ) ;
809+ PropertyInfo idprop = _modelManager . GetIdProperty ( type ) ;
803810 idprop . SetValue ( retval , System . Convert . ChangeType ( id , idprop . PropertyType ) ) ;
804811 return retval ;
805812 }
@@ -828,7 +835,7 @@ protected string GetValueForIdProperty(PropertyInfo idprop, object obj)
828835 protected string GetIdFor ( object obj )
829836 {
830837 Type type = obj . GetType ( ) ;
831- PropertyInfo idprop = ModelManager . Instance . GetIdProperty ( type ) ;
838+ PropertyInfo idprop = _modelManager . GetIdProperty ( type ) ;
832839 return GetValueForIdProperty ( idprop , obj ) ;
833840 }
834841
0 commit comments