Skip to content

Add IMvcBuilder Overload to IServiceCollectionExtensions #75

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 1 commit into from
Mar 25, 2017
Merged
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
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