Skip to content

v1.2.2 Extensibility Updates #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ namespace JsonApiDotNetCore.Routing
{
public static class IApplicationBuilderExtensions
{
public static IApplicationBuilder UseJsonApi(this IApplicationBuilder app)
public static IApplicationBuilder UseJsonApi(this IApplicationBuilder app, bool useMvc = true)
{
app.UseMiddleware<RequestMiddleware>();

app.UseMvc();
if (useMvc)
app.UseMvc();

return app;
}
Expand Down
26 changes: 21 additions & 5 deletions src/JsonApiDotNetCore/Extensions/IServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,38 @@ public static class IServiceCollectionExtensions
public static void AddJsonApi<TContext>(this IServiceCollection services)
where TContext : DbContext
{
_addInternals<TContext>(services, new JsonApiOptions());
var mvcBuilder = services.AddMvc();
AddInternals<TContext>(services, new JsonApiOptions(), mvcBuilder);
}

public static void AddJsonApi<TContext>(this IServiceCollection services, Action<JsonApiOptions> options)
where TContext : DbContext
{
var config = new JsonApiOptions();

options(config);
_addInternals<TContext>(services, config);

var mvcBuilder = services.AddMvc();
AddInternals<TContext>(services, config, mvcBuilder);
}

private static void _addInternals<TContext>(IServiceCollection services, JsonApiOptions jsonApiOptions)
where TContext : DbContext
public static void AddJsonApi<TContext>(this IServiceCollection services,
Action<JsonApiOptions> options,
IMvcBuilder mvcBuilder) where TContext : DbContext
{
var config = new JsonApiOptions();

options(config);

AddInternals<TContext>(services, config, mvcBuilder);
}

private static void AddInternals<TContext>(IServiceCollection services,
JsonApiOptions jsonApiOptions,
IMvcBuilder mvcBuilder) where TContext : DbContext
{
services.AddJsonApiInternals<TContext>(jsonApiOptions);
services.AddMvc()
mvcBuilder
.AddMvcOptions(opt => {
opt.Filters.Add(typeof(JsonApiExceptionFilter));
opt.SerializeAsJsonApi(jsonApiOptions);
Expand Down
2 changes: 1 addition & 1 deletion src/JsonApiDotNetCore/JsonApiDotNetCore.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<VersionPrefix>1.2.1</VersionPrefix>
<VersionPrefix>1.2.2</VersionPrefix>
<TargetFramework>netcoreapp1.0</TargetFramework>
<AssemblyName>JsonApiDotNetCore</AssemblyName>
<PackageId>JsonApiDotNetCore</PackageId>
Expand Down