1- using System . Collections . Generic ;
1+ using System ;
2+ using System . Collections . Generic ;
23using System . Web . Http ;
34using System . Web . Http . Dispatcher ;
45using System . Web . Http . Filters ;
@@ -19,6 +20,7 @@ public class JsonApiConfiguration
1920 private bool _enableFiltering ;
2021 private bool _enableSorting ;
2122 private IPluralizationService _pluralizationService ;
23+ private IList < Type > _resourceTypes ;
2224
2325 /// <summary>
2426 /// Creates a new configuration
@@ -27,11 +29,11 @@ public JsonApiConfiguration()
2729 {
2830 Builder = new ContainerBuilder ( ) ;
2931 Builder . RegisterType < JsonApiQueryableAttribute > ( ) . SingleInstance ( ) ;
30- Builder . RegisterType < ModelManager > ( ) . As < IModelManager > ( ) . SingleInstance ( ) ;
3132 Builder . Register ( c => new JsonApiFormatter ( c . Resolve < IModelManager > ( ) ) ) . SingleInstance ( ) ;
3233
3334 _enableFiltering = true ;
3435 _enableSorting = true ;
36+ _resourceTypes = new List < Type > ( ) ;
3537 }
3638
3739 /// <summary>
@@ -65,6 +67,17 @@ public JsonApiConfiguration PluralizeResourceTypesWith(IPluralizationService plu
6567 return this ;
6668 }
6769
70+ /// <summary>
71+ ///
72+ /// </summary>
73+ /// <param name="type"></param>
74+ /// <returns></returns>
75+ public JsonApiConfiguration RegisterResourceType ( Type type )
76+ {
77+ _resourceTypes . Add ( type ) ;
78+ return this ;
79+ }
80+
6881 /// <summary>
6982 /// Applies the running configuration to an HttpConfiguration instance
7083 /// </summary>
@@ -79,8 +92,17 @@ public void Apply(HttpConfiguration httpConfig)
7992 if ( _enableSorting )
8093 Builder . RegisterType < SortingQueryableTransformer > ( ) ;
8194
95+ Builder . RegisterType < ModelManager > ( ) . As < ModelManager > ( ) . As < IModelManager > ( ) . SingleInstance ( ) ;
96+
8297 var container = Builder . Build ( ) ;
8398
99+ // Register our types
100+ var modelManager = container . Resolve < ModelManager > ( ) ;
101+ foreach ( var resourceType in _resourceTypes )
102+ {
103+ modelManager . RegisterResourceType ( resourceType ) ;
104+ }
105+
84106 using ( var lifetimeScope = container . BeginLifetimeScope ( ) )
85107 {
86108 var formatter = lifetimeScope . Resolve < JsonApiFormatter > ( ) ;
0 commit comments