Skip to content

Commit 6eb994f

Browse files
Ensure depend services are added
1 parent 215b04e commit 6eb994f

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/AspNetCore/WebApi/src/Asp.Versioning.Mvc.ApiExplorer/DependencyInjection/IApiVersioningBuilderExtensions.cs

+8-9
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static IApiVersioningBuilder AddApiExplorer( this IApiVersioningBuilder b
3131
throw new ArgumentNullException( nameof( builder ) );
3232
}
3333

34-
AddApiExplorerServices( builder.Services );
34+
AddApiExplorerServices( builder );
3535
return builder;
3636
}
3737

@@ -48,18 +48,17 @@ public static IApiVersioningBuilder AddApiExplorer( this IApiVersioningBuilder b
4848
throw new ArgumentNullException( nameof( builder ) );
4949
}
5050

51-
var services = builder.Services;
52-
AddApiExplorerServices( services );
53-
services.Configure( setupAction );
51+
AddApiExplorerServices( builder );
52+
builder.Services.Configure( setupAction );
53+
5454
return builder;
5555
}
5656

57-
private static void AddApiExplorerServices( IServiceCollection services )
57+
private static void AddApiExplorerServices( IApiVersioningBuilder builder )
5858
{
59-
if ( services == null )
60-
{
61-
throw new ArgumentNullException( nameof( services ) );
62-
}
59+
builder.AddMvc();
60+
61+
var services = builder.Services;
6362

6463
services.AddMvcCore().AddApiExplorer();
6564
services.TryAddSingleton<IOptionsFactory<ApiExplorerOptions>, ApiExplorerOptionsFactory<ApiExplorerOptions>>();

src/AspNetCore/WebApi/src/Asp.Versioning.Mvc/DependencyInjection/IApiVersioningBuilderExtensions.cs

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public static IApiVersioningBuilder AddMvc( this IApiVersioningBuilder builder,
6262

6363
private static void AddServices( IServiceCollection services )
6464
{
65+
services.AddMvcCore();
6566
services.TryAddSingleton<IOptionsFactory<MvcApiVersioningOptions>, MvcApiVersioningOptionsFactory<MvcApiVersioningOptions>>();
6667
services.TryAddSingleton<IControllerNameConvention, DefaultControllerNameConvention>();
6768
services.TryAddSingleton<IApiVersionConventionBuilder>( sp => new ApiVersionConventionBuilder( sp.GetRequiredService<IControllerNameConvention>() ) );

0 commit comments

Comments
 (0)