Skip to content

Commit 8894e3a

Browse files
Chris Martinezcommonsensesoftware
authored andcommitted
Ensure VersionedMetadataController assembly is registered with PartManager. Resolves #551.
1 parent d42f3b7 commit 8894e3a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/Microsoft.AspNetCore.OData.Versioning/Extensions.DependencyInjection/IODataBuilderExtensions.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,15 @@ public static IODataBuilder EnableApiVersioning( this IODataBuilder builder, Act
5959

6060
static void AddODataServices( IServiceCollection services )
6161
{
62-
// note: if we end up creating a new ApplicationPartManager here we won't fail, but the setup
63-
// will not register any model configurations automatically. this is almost certainly because
64-
// services.AddMvcCore() hasn't be called yet, which is unexpected
65-
var partManager = services.GetService<ApplicationPartManager>() ?? new ApplicationPartManager();
62+
var partManager = services.GetService<ApplicationPartManager>();
63+
64+
if ( partManager == null )
65+
{
66+
partManager = new ApplicationPartManager();
67+
services.TryAddSingleton( partManager );
68+
}
69+
70+
partManager.ApplicationParts.Add( new AssemblyPart( typeof( IODataBuilderExtensions ).Assembly ) );
6671

6772
ConfigureDefaultFeatureProviders( partManager );
6873
services.Replace( Singleton<IActionSelector, ODataApiVersionActionSelector>() );

0 commit comments

Comments
 (0)