Skip to content

Commit 1c7938c

Browse files
authored
Merge pull request #76 from Research-Institute/develop
v1.2.2 Extensibility Updates
2 parents 2a8c633 + 8a14139 commit 1c7938c

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

src/JsonApiDotNetCore/Extensions/IApplicationBuilderExtensions.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ namespace JsonApiDotNetCore.Routing
55
{
66
public static class IApplicationBuilderExtensions
77
{
8-
public static IApplicationBuilder UseJsonApi(this IApplicationBuilder app)
8+
public static IApplicationBuilder UseJsonApi(this IApplicationBuilder app, bool useMvc = true)
99
{
1010
app.UseMiddleware<RequestMiddleware>();
1111

12-
app.UseMvc();
12+
if (useMvc)
13+
app.UseMvc();
1314

1415
return app;
1516
}

src/JsonApiDotNetCore/Extensions/IServiceCollectionExtensions.cs

+21-5
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,38 @@ public static class IServiceCollectionExtensions
1818
public static void AddJsonApi<TContext>(this IServiceCollection services)
1919
where TContext : DbContext
2020
{
21-
_addInternals<TContext>(services, new JsonApiOptions());
21+
var mvcBuilder = services.AddMvc();
22+
AddInternals<TContext>(services, new JsonApiOptions(), mvcBuilder);
2223
}
2324

2425
public static void AddJsonApi<TContext>(this IServiceCollection services, Action<JsonApiOptions> options)
2526
where TContext : DbContext
2627
{
2728
var config = new JsonApiOptions();
29+
2830
options(config);
29-
_addInternals<TContext>(services, config);
31+
32+
var mvcBuilder = services.AddMvc();
33+
AddInternals<TContext>(services, config, mvcBuilder);
3034
}
3135

32-
private static void _addInternals<TContext>(IServiceCollection services, JsonApiOptions jsonApiOptions)
33-
where TContext : DbContext
36+
public static void AddJsonApi<TContext>(this IServiceCollection services,
37+
Action<JsonApiOptions> options,
38+
IMvcBuilder mvcBuilder) where TContext : DbContext
39+
{
40+
var config = new JsonApiOptions();
41+
42+
options(config);
43+
44+
AddInternals<TContext>(services, config, mvcBuilder);
45+
}
46+
47+
private static void AddInternals<TContext>(IServiceCollection services,
48+
JsonApiOptions jsonApiOptions,
49+
IMvcBuilder mvcBuilder) where TContext : DbContext
3450
{
3551
services.AddJsonApiInternals<TContext>(jsonApiOptions);
36-
services.AddMvc()
52+
mvcBuilder
3753
.AddMvcOptions(opt => {
3854
opt.Filters.Add(typeof(JsonApiExceptionFilter));
3955
opt.SerializeAsJsonApi(jsonApiOptions);

src/JsonApiDotNetCore/JsonApiDotNetCore.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<VersionPrefix>1.2.1</VersionPrefix>
4+
<VersionPrefix>1.2.2</VersionPrefix>
55
<TargetFramework>netcoreapp1.0</TargetFramework>
66
<AssemblyName>JsonApiDotNetCore</AssemblyName>
77
<PackageId>JsonApiDotNetCore</PackageId>

0 commit comments

Comments
 (0)