Skip to content

Cleanup of public overloads for ILoggerFactory #674

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 8 commits into from
Feb 13, 2020
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 @@ -2,15 +2,17 @@
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Controllers;
using JsonApiDotNetCore.Services;
using Microsoft.Extensions.Logging;

namespace GettingStarted
{
public class ArticlesController : JsonApiController<Article>
{
public ArticlesController(
IJsonApiOptions jsonApiOptions,
ILoggerFactory loggerFactory,
IResourceService<Article> resourceService)
: base(jsonApiOptions, resourceService)
: base(jsonApiOptions, loggerFactory, resourceService)
{ }
}
}
4 changes: 3 additions & 1 deletion src/Examples/GettingStarted/Controllers/PeopleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Controllers;
using JsonApiDotNetCore.Services;
using Microsoft.Extensions.Logging;

namespace GettingStarted
{
public class PeopleController : JsonApiController<Person>
{
public PeopleController(
IJsonApiOptions jsonApiOptions,
ILoggerFactory loggerFactory,
IResourceService<Person> resourceService)
: base(jsonApiOptions, resourceService)
: base(jsonApiOptions, loggerFactory, resourceService)
{ }
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Controllers;
using JsonApiDotNetCore.Services;
using Microsoft.Extensions.Logging;

namespace GettingStarted.ResourceDefinitionExample
{
public class ModelsController : JsonApiController<Model>
{
public ModelsController(
IJsonApiOptions jsonApiOptions,
ILoggerFactory loggerFactory,
IResourceService<Model> resourceService)
: base(jsonApiOptions, resourceService)
: base(jsonApiOptions, loggerFactory, resourceService)
{ }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
using JsonApiDotNetCore.Controllers;
using JsonApiDotNetCore.Services;
using JsonApiDotNetCoreExample.Models;
using Microsoft.Extensions.Logging;

namespace JsonApiDotNetCoreExample.Controllers
{
public class ArticlesController : JsonApiController<Article>
{
public ArticlesController(
IJsonApiOptions jsonApiOptions,
IResourceService<Article> resourceService)
: base(jsonApiOptions, resourceService)
ILoggerFactory loggerFactory,
IResourceService<Article> resourceService)
: base(jsonApiOptions, loggerFactory, resourceService)
{ }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public class KebabCasedModelsController : JsonApiController<KebabCasedModel>
{
public KebabCasedModelsController(
IJsonApiOptions jsonApiOptions,
IResourceService<KebabCasedModel> resourceService,
ILoggerFactory loggerFactory)
: base(jsonApiOptions, resourceService, loggerFactory)
ILoggerFactory loggerFactory,
IResourceService<KebabCasedModel> resourceService)
: base(jsonApiOptions, loggerFactory, resourceService)
{ }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ namespace JsonApiDotNetCoreExample.Controllers
{
public class PassportsController : JsonApiController<Passport>
{
public PassportsController(IJsonApiOptions jsonApiOptions,
IResourceService<Passport, int> resourceService,
ILoggerFactory loggerFactory = null)
: base(jsonApiOptions, resourceService, loggerFactory)
{
}
public PassportsController(
IJsonApiOptions jsonApiOptions,
ILoggerFactory loggerFactory,
IResourceService<Passport, int> resourceService)
: base(jsonApiOptions, loggerFactory, resourceService)
{ }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public class PeopleController : JsonApiController<Person>
{
public PeopleController(
IJsonApiOptions jsonApiOptions,
IResourceService<Person> resourceService,
ILoggerFactory loggerFactory)
: base(jsonApiOptions, resourceService, loggerFactory)
ILoggerFactory loggerFactory,
IResourceService<Person> resourceService)
: base(jsonApiOptions, loggerFactory, resourceService)
{ }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public class PersonRolesController : JsonApiController<PersonRole>
{
public PersonRolesController(
IJsonApiOptions jsonApiOptions,
IResourceService<PersonRole> resourceService,
ILoggerFactory loggerFactory)
: base(jsonApiOptions, resourceService, loggerFactory)
ILoggerFactory loggerFactory,
IResourceService<PersonRole> resourceService)
: base(jsonApiOptions, loggerFactory, resourceService)
{ }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public class TagsController : JsonApiController<Tag>
{
public TagsController(
IJsonApiOptions jsonApiOptions,
IResourceService<Tag> resourceService,
ILoggerFactory loggerFactory)
: base(jsonApiOptions, resourceService, loggerFactory)
ILoggerFactory loggerFactory,
IResourceService<Tag, int> resourceService)
: base(jsonApiOptions, loggerFactory, resourceService)
{ }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Controllers;
using JsonApiDotNetCore.Data;
using JsonApiDotNetCore.Internal.Contracts;
using JsonApiDotNetCore.Services;
using JsonApiDotNetCoreExample.Models;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -18,11 +17,11 @@ public class TodoCollectionsController : JsonApiController<TodoItemCollection, G
readonly IDbContextResolver _dbResolver;

public TodoCollectionsController(
IJsonApiOptions jsonApiOptions,
IDbContextResolver contextResolver,
IResourceService<TodoItemCollection, Guid> resourceService,
ILoggerFactory loggerFactory)
: base(jsonApiOptions, resourceService, loggerFactory)
IJsonApiOptions jsonApiOptions,
ILoggerFactory loggerFactory,
IDbContextResolver contextResolver,
IResourceService<TodoItemCollection, Guid> resourceService)
: base(jsonApiOptions, loggerFactory, resourceService)
{
_dbResolver = contextResolver;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public class TodoItemsController : JsonApiController<TodoItem>
{
public TodoItemsController(
IJsonApiOptions jsonApiOptions,
IResourceService<TodoItem> resourceService,
ILoggerFactory loggerFactory)
: base(jsonApiOptions, resourceService, loggerFactory)
ILoggerFactory loggerFactory,
IResourceService<TodoItem> resourceService)
: base(jsonApiOptions, loggerFactory, resourceService)
{ }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public abstract class AbstractTodoItemsController<T>
{
protected AbstractTodoItemsController(
IJsonApiOptions jsonApiOptions,
IResourceService<T, int> service,
ILoggerFactory loggerFactory)
: base(jsonApiOptions, service, loggerFactory)
ILoggerFactory loggerFactory,
IResourceService<T, int> service)
: base(jsonApiOptions, loggerFactory, service)
{ }
}

Expand All @@ -24,9 +24,9 @@ public class TodoItemsTestController : AbstractTodoItemsController<TodoItem>
{
public TodoItemsTestController(
IJsonApiOptions jsonApiOptions,
IResourceService<TodoItem> service,
ILoggerFactory loggerFactory)
: base(jsonApiOptions, service, loggerFactory)
ILoggerFactory loggerFactory,
IResourceService<TodoItem> service)
: base(jsonApiOptions, loggerFactory, service)
{ }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ public class UsersController : JsonApiController<User>
{
public UsersController(
IJsonApiOptions jsonApiOptions,
IResourceService<User> resourceService,
ILoggerFactory loggerFactory)
: base(jsonApiOptions, resourceService, loggerFactory)
ILoggerFactory loggerFactory,
IResourceService<User> resourceService)
: base(jsonApiOptions, loggerFactory, resourceService)
{ }
}

public class SuperUsersController : JsonApiController<SuperUser>
{
public SuperUsersController(
IJsonApiOptions jsonApiOptions,
IResourceService<SuperUser> resourceService,
ILoggerFactory loggerFactory)
: base(jsonApiOptions, resourceService, loggerFactory)
ILoggerFactory loggerFactory,
IResourceService<SuperUser> resourceService)
: base(jsonApiOptions, loggerFactory, resourceService)
{ }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ namespace JsonApiDotNetCoreExample.Services
{
public class CustomArticleService : DefaultResourceService<Article>
{
public CustomArticleService(IEnumerable<IQueryParameterService> queryParameters,
IJsonApiOptions options,
IResourceRepository<Article, int> repository,
IResourceContextProvider provider,
IResourceHookExecutor hookExecutor = null,
ILoggerFactory loggerFactory = null)
: base(queryParameters, options, repository, provider, hookExecutor, loggerFactory) { }
public CustomArticleService(
IEnumerable<IQueryParameterService> queryParameters,
IJsonApiOptions options,
ILoggerFactory loggerFactory,
IResourceRepository<Article, int> repository,
IResourceContextProvider provider,
IResourceHookExecutor hookExecutor = null)
: base(queryParameters, options, loggerFactory, repository, provider, hookExecutor)
{ }

public override async Task<Article> GetAsync(int id)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using JsonApiDotNetCoreExample.Data;
using Microsoft.EntityFrameworkCore;
using JsonApiDotNetCore.Extensions;
Expand All @@ -18,14 +17,8 @@ public NoDefaultPageSizeStartup(IWebHostEnvironment env) : base(env) { }

public override void ConfigureServices(IServiceCollection services)
{
var loggerFactory = new LoggerFactory();
var mvcBuilder = services.AddMvcCore();
services
.AddSingleton<ILoggerFactory>(loggerFactory)
.AddLogging(builder =>
{
builder.AddConsole();
})
.AddDbContext<AppDbContext>(options => options.UseNpgsql(GetDbConnectionString()), ServiceLifetime.Transient)
.AddJsonApi(options => {
options.Namespace = "api/v1";
Expand Down
15 changes: 3 additions & 12 deletions src/Examples/JsonApiDotNetCoreExample/Startups/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using JsonApiDotNetCoreExample.Data;
using Microsoft.EntityFrameworkCore;
using JsonApiDotNetCore.Extensions;
using System;
using Microsoft.Extensions.Logging.Debug;

namespace JsonApiDotNetCoreExample
{
Expand All @@ -27,19 +25,12 @@ public Startup(IWebHostEnvironment env)

public virtual void ConfigureServices(IServiceCollection services)
{
var loggerFactory = new LoggerFactory();
services
.AddSingleton<ILoggerFactory>(loggerFactory)
.AddLogging(builder =>
{
builder.AddConsole();
builder.AddConfiguration(Config.GetSection("Logging"));
})
.AddDbContext<AppDbContext>(options =>
{
options.UseLoggerFactory(new LoggerFactory(new[] { new DebugLoggerProvider() }))
.EnableSensitiveDataLogging()
.UseNpgsql(GetDbConnectionString(), options => options.SetPostgresVersion(new Version(9,6)));
options
.EnableSensitiveDataLogging()
.UseNpgsql(GetDbConnectionString(), options => options.SetPostgresVersion(new Version(9,6)));
}, ServiceLifetime.Transient)
.AddJsonApi(options =>
{
Expand Down
2 changes: 1 addition & 1 deletion src/Examples/JsonApiDotNetCoreExample/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning",
"Default": "Debug",
"System": "Warning",
"Microsoft": "Warning",
"Microsoft.EntityFrameworkCore": "Debug"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public class TodoItemsController : JsonApiController<TodoItem>
{
public TodoItemsController(
IJsonApiOptions jsonApiOptions,
IResourceService<TodoItem> resourceService,
ILoggerFactory loggerFactory)
: base(jsonApiOptions, resourceService, loggerFactory)
ILoggerFactory loggerFactory,
IResourceService<TodoItem> resourceService)
: base(jsonApiOptions, loggerFactory, resourceService)
{ }
}
}
7 changes: 1 addition & 6 deletions src/Examples/NoEntityFrameworkExample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NoEntityFrameworkExample.Services;
using Microsoft.EntityFrameworkCore;
using NoEntityFrameworkExample.Data;
Expand All @@ -31,11 +30,7 @@ public virtual void ConfigureServices(IServiceCollection services)
{
// Add framework services.
var mvcBuilder = services.AddMvcCore();
services.AddLogging(builder =>
{
builder.AddConfiguration(Configuration.GetSection("Logging"));
builder.AddConsole();
}).AddJsonApi(
services.AddJsonApi(
options => options.Namespace = "api/v1",
resources: resources => resources.AddResource<TodoItem>("todoItems"),
mvcBuilder: mvcBuilder
Expand Down
12 changes: 7 additions & 5 deletions src/Examples/ReportsExample/Controllers/ReportsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
using Microsoft.AspNetCore.Mvc;
using JsonApiDotNetCore.Controllers;
using JsonApiDotNetCore.Services;
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Internal.Contracts;

using JsonApiDotNetCore.Configuration;
using Microsoft.Extensions.Logging;
using ReportsExample.Models;

namespace ReportsExample.Controllers
{
[Route("api/[controller]")]
public class ReportsController : BaseJsonApiController<Report, int>
{
public ReportsController(
IJsonApiOptions jsonApiOptions,
IJsonApiOptions jsonApiOptions,
ILoggerFactory loggerFactory,
IGetAllService<Report> getAll)
: base(jsonApiOptions, getAll: getAll)
: base(jsonApiOptions, loggerFactory, getAll)
{ }

[HttpGet]
Expand Down
Loading