Skip to content

Renaming and consistency #587

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

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0ced9da
refactor: move HasManyThrough GetValue and SetValue logic to HasManyT…
maurei Oct 21, 2019
2e94d8e
feat: remove GetPublicAttributeName from ResourceGraph and remove dep…
maurei Oct 21, 2019
e2c5be0
style: spacing in BaseJsonApiController<,>
maurei Oct 21, 2019
baa77ee
feat: remove GetEntityFromControllerName from ResourceGraph
maurei Oct 21, 2019
85ee717
feat: remove GetInverseRelationship from ResourceGraph
maurei Oct 21, 2019
a352f08
feat: decouples UsesDbContext from ResourceGraph and introduces decou…
maurei Oct 21, 2019
b5c38d4
chore: remove redundant injections of IResourceGraph
maurei Oct 21, 2019
be08867
refactor: merge IContextEntityProvider and IFieldsExplorer into IReso…
maurei Oct 21, 2019
76cf896
style: cleanup of variable names
maurei Oct 21, 2019
95d8707
chore: various fixes for PR review, mostly style and variable naming
maurei Oct 21, 2019
a7618f6
style: rename IResourceGraphExplorer back to IResourceGraph, consiten…
maurei Oct 22, 2019
0230b6c
docs: comments for DefaultActionFilter and DefaultTypeFilter
maurei Oct 22, 2019
1ad32fa
docs: comments JsonApiApplicationBuilder
maurei Oct 22, 2019
c2d6417
style: consistent variable naming|
maurei Oct 22, 2019
b4baf91
chore: wire up IControllerResourceMapping
maurei Oct 22, 2019
f22d932
refactor: routing convention implements controller mapping interface
maurei Oct 22, 2019
2302fcb
chore: fix merge
maurei Oct 22, 2019
833da6a
style: DefaultResourceRepository and DefaultEntityService as consiste…
maurei Oct 22, 2019
519513d
style: rename old repository interfaces
maurei Oct 22, 2019
d038582
style: ContextEntity --> ResourceContext
maurei Oct 22, 2019
f2e411c
style: rename Entity to Resource
maurei Oct 22, 2019
3af6f9b
style: TEntity --> TResource
maurei Oct 22, 2019
ce08b4f
style: DependentType, PrincipalType --> RightType, LeftType
maurei Oct 22, 2019
b162519
style: replaced principal with left and dependent with right whenever…
maurei Oct 22, 2019
e509956
chore: remove redundant bindings throughout entire codebase
maurei Oct 22, 2019
48495d3
refactor: regroupe hook container and executors
maurei Oct 22, 2019
f19e606
style: IGenericProcessor --> IHasManyThroughUpdateHelper
maurei Oct 22, 2019
7d235ab
chore: delete rogue file
maurei Oct 22, 2019
6a186a5
style: rename GenericProcessorFactory --> GenericServiceFactory
maurei Oct 22, 2019
354a1be
chore: fix NoEntityFrameworkExample project
maurei Oct 22, 2019
e55395c
Merge branch 'dev-v4' into chore/renaming
maurei Oct 22, 2019
d205505
fix: merge
maurei Oct 22, 2019
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
2 changes: 1 addition & 1 deletion benchmarks/Query/QueryParser_Benchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class QueryParser_Benchmarks {

public QueryParser_Benchmarks() {
var requestMock = new Mock<IRequestContext>();
requestMock.Setup(m => m.GetRequestResource()).Returns(new ContextEntity {
requestMock.Setup(m => m.GetRequestResource()).Returns(new ResourceContext {
Attributes = new List<AttrAttribute> {
new AttrAttribute(ATTRIBUTE, ATTRIBUTE)
}
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/Serialization/JsonApiSerializer_Benchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
// jsonApiOptions.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
// jsonApiContextMock.Setup(m => m.Options).Returns(jsonApiOptions);

// var genericProcessorFactoryMock = new Mock<IGenericProcessorFactory>();
// var genericServiceFactoryMock = new Mock<IgenericServiceFactory>();

// var documentBuilder = new BaseDocumentBuilder(jsonApiContextMock.Object);
// _jsonApiSerializer = new JsonApiSerializer(jsonApiContextMock.Object, documentBuilder);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using GettingStarted.Models;
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Controllers;
using JsonApiDotNetCore.Internal.Contracts;
using JsonApiDotNetCore.Services;

namespace GettingStarted
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using GettingStarted.Models;
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Controllers;
using JsonApiDotNetCore.Internal.Contracts;
using JsonApiDotNetCore.Services;

namespace GettingStarted
Expand Down
5 changes: 1 addition & 4 deletions src/Examples/GettingStarted/Data/SampleDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ namespace GettingStarted
{
public class SampleDbContext : DbContext
{
public SampleDbContext(DbContextOptions<SampleDbContext> options)
: base(options)
{ }

public SampleDbContext(DbContextOptions<SampleDbContext> options) : base(options) { }
public DbSet<Article> Articles { get; set; }
public DbSet<Person> People { get; set; }
public DbSet<Model> Models { get; set; }
Expand Down
1 change: 0 additions & 1 deletion src/Examples/GettingStarted/Models/Person.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ public class Person : Identifiable
{
[Attr]
public string Name { get; set; }

[HasMany]
public List<Article> Articles { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ namespace GettingStarted.ResourceDefinitionExample
{
public class ModelDefinition : ResourceDefinition<Model>
{
public ModelDefinition(IContextEntityProvider provider) : base(provider)
public ModelDefinition(IResourceGraph resourceGraph) : base(resourceGraph)
{
// this allows POST / PATCH requests to set the value of a
// property, but we don't include this value in the response
// this might be used if the incoming value gets hashed or
// encrypted prior to being persisted and this value should
// never be sent back to the client
HideFields(model => model.DontExpose);
}

// this allows POST / PATCH requests to set the value of a
// property, but we don't include this value in the response
// this might be used if the incoming value gets hashed or
// encrypted prior to being persisted and this value should
// never be sent back to the client
protected override List<AttrAttribute> OutputAttrs()
=> Remove(model => model.DontExpose);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Controllers;
using JsonApiDotNetCore.Internal.Contracts;
using JsonApiDotNetCore.Services;

namespace GettingStarted.ResourceDefinitionExample
Expand Down
9 changes: 2 additions & 7 deletions src/Examples/GettingStarted/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.EntityFrameworkCore;
using JsonApiDotNetCore.Extensions;
Expand All @@ -23,7 +18,7 @@ public void ConfigureServices(IServiceCollection services)
var mvcBuilder = services.AddMvcCore();
services.AddJsonApi(
options => options.Namespace = "api",
discover => discover.AddCurrentAssembly(), mvcBuilder);
discover => discover.AddCurrentAssembly(), mvcBuilder: mvcBuilder);
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env, SampleDbContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@

namespace JsonApiDotNetCoreExample.Services
{
public class CustomArticleService : EntityResourceService<Article>
public class CustomArticleService : DefaultResourceService<Article>
{
public CustomArticleService(ISortService sortService,
IFilterService filterService,
IEntityRepository<Article, int> repository,
IResourceRepository<Article, int> repository,
IJsonApiOptions options,
IIncludeService includeService,
ISparseFieldsService sparseFieldsService,
IPageService pageService,
IContextEntityProvider provider,
IResourceContextProvider provider,
IResourceHookExecutor hookExecutor = null,
ILoggerFactory loggerFactory = null)
: base(sortService, filterService, repository, options, includeService, sparseFieldsService,
Expand Down
8 changes: 4 additions & 4 deletions src/JsonApiDotNetCore/Builders/IResourceGraphBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Graph;
using JsonApiDotNetCore.Internal;
using JsonApiDotNetCore.Internal.Contracts;
using JsonApiDotNetCore.Models;
Expand All @@ -21,7 +21,7 @@ public interface IResourceGraphBuilder
/// <param name="pluralizedTypeName">
/// The pluralized name that should be exposed by the API.
/// If nothing is specified, the configured name formatter will be used.
/// See <see cref="JsonApiOptions.ResourceNameFormatter" />.
/// See <see cref="IResourceNameFormatter" />.
/// </param>
IResourceGraphBuilder AddResource<TResource>(string pluralizedTypeName = null) where TResource : class, IIdentifiable<int>;

Expand All @@ -34,7 +34,7 @@ public interface IResourceGraphBuilder
/// <param name="pluralizedTypeName">
/// The pluralized name that should be exposed by the API.
/// If nothing is specified, the configured name formatter will be used.
/// See <see cref="JsonApiOptions.ResourceNameFormatter" />.
/// See <see cref="IResourceNameFormatter" />.
/// </param>
IResourceGraphBuilder AddResource<TResource, TId>(string pluralizedTypeName = null) where TResource : class, IIdentifiable<TId>;

Expand All @@ -46,7 +46,7 @@ public interface IResourceGraphBuilder
/// <param name="pluralizedTypeName">
/// The pluralized name that should be exposed by the API.
/// If nothing is specified, the configured name formatter will be used.
/// See <see cref="JsonApiOptions.ResourceNameFormatter" />.
/// See <see cref="IResourceNameFormatter" />.
/// </param>
IResourceGraphBuilder AddResource(Type entityType, Type idType, string pluralizedTypeName = null);

Expand Down
44 changes: 22 additions & 22 deletions src/JsonApiDotNetCore/Builders/JsonApiApplicationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void ConfigureMvc()

var routingConvention = intermediateProvider.GetRequiredService<IJsonApiRoutingConvention>();
_mvcBuilder.AddMvcOptions(opt => opt.Conventions.Insert(0, routingConvention));
_services.AddSingleton<IControllerResourceMapping>(routingConvention);
_services.AddSingleton<IControllerResourceMapping>(routingConvention);
}

/// <summary>
Expand Down Expand Up @@ -118,44 +118,44 @@ public void ConfigureServices()
_services.AddSingleton(new DbContextOptionsBuilder().Options);
}

_services.AddScoped(typeof(IEntityRepository<>), typeof(DefaultEntityRepository<>));
_services.AddScoped(typeof(IEntityRepository<,>), typeof(DefaultEntityRepository<,>));
_services.AddScoped(typeof(IResourceRepository<>), typeof(DefaultResourceRepository<>));
_services.AddScoped(typeof(IResourceRepository<,>), typeof(DefaultResourceRepository<,>));

_services.AddScoped(typeof(IEntityReadRepository<,>), typeof(DefaultEntityRepository<,>));
_services.AddScoped(typeof(IEntityWriteRepository<,>), typeof(DefaultEntityRepository<,>));
_services.AddScoped(typeof(IResourceReadRepository<,>), typeof(DefaultResourceRepository<,>));
_services.AddScoped(typeof(IResourceWriteRepository<,>), typeof(DefaultResourceRepository<,>));

_services.AddScoped(typeof(ICreateService<>), typeof(EntityResourceService<>));
_services.AddScoped(typeof(ICreateService<,>), typeof(EntityResourceService<,>));
_services.AddScoped(typeof(ICreateService<>), typeof(DefaultResourceService<>));
_services.AddScoped(typeof(ICreateService<,>), typeof(DefaultResourceService<,>));

_services.AddScoped(typeof(IGetAllService<>), typeof(EntityResourceService<>));
_services.AddScoped(typeof(IGetAllService<,>), typeof(EntityResourceService<,>));
_services.AddScoped(typeof(IGetAllService<>), typeof(DefaultResourceService<>));
_services.AddScoped(typeof(IGetAllService<,>), typeof(DefaultResourceService<,>));

_services.AddScoped(typeof(IGetByIdService<>), typeof(EntityResourceService<>));
_services.AddScoped(typeof(IGetByIdService<,>), typeof(EntityResourceService<,>));
_services.AddScoped(typeof(IGetByIdService<>), typeof(DefaultResourceService<>));
_services.AddScoped(typeof(IGetByIdService<,>), typeof(DefaultResourceService<,>));

_services.AddScoped(typeof(IGetRelationshipService<,>), typeof(EntityResourceService<>));
_services.AddScoped(typeof(IGetRelationshipService<,>), typeof(EntityResourceService<,>));
_services.AddScoped(typeof(IGetRelationshipService<,>), typeof(DefaultResourceService<>));
_services.AddScoped(typeof(IGetRelationshipService<,>), typeof(DefaultResourceService<,>));

_services.AddScoped(typeof(IUpdateService<>), typeof(EntityResourceService<>));
_services.AddScoped(typeof(IUpdateService<,>), typeof(EntityResourceService<,>));
_services.AddScoped(typeof(IUpdateService<>), typeof(DefaultResourceService<>));
_services.AddScoped(typeof(IUpdateService<,>), typeof(DefaultResourceService<,>));

_services.AddScoped(typeof(IDeleteService<>), typeof(EntityResourceService<>));
_services.AddScoped(typeof(IDeleteService<,>), typeof(EntityResourceService<,>));
_services.AddScoped(typeof(IDeleteService<>), typeof(DefaultResourceService<>));
_services.AddScoped(typeof(IDeleteService<,>), typeof(DefaultResourceService<,>));

_services.AddScoped(typeof(IResourceService<>), typeof(EntityResourceService<>));
_services.AddScoped(typeof(IResourceService<,>), typeof(EntityResourceService<,>));
_services.AddScoped(typeof(IResourceService<>), typeof(DefaultResourceService<>));
_services.AddScoped(typeof(IResourceService<,>), typeof(DefaultResourceService<,>));

_services.AddSingleton<ILinksConfiguration>(JsonApiOptions);
_services.AddSingleton(resourceGraph);
_services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
_services.AddSingleton<IResourceGraph>(resourceGraph);
_services.AddSingleton<IContextEntityProvider>(resourceGraph);
_services.AddSingleton<IResourceContextProvider>(resourceGraph);
_services.AddScoped<ICurrentRequest, CurrentRequest>();
_services.AddScoped<IScopedServiceProvider, RequestScopedServiceProvider>();
_services.AddScoped<IJsonApiWriter, JsonApiWriter>();
_services.AddScoped<IJsonApiReader, JsonApiReader>();
_services.AddScoped<IGenericProcessorFactory, GenericProcessorFactory>();
_services.AddScoped(typeof(GenericProcessor<>));
_services.AddScoped<IGenericServiceFactory, GenericServiceFactory>();
_services.AddScoped(typeof(HasManyThroughUpdateHelper<>));
_services.AddScoped<IQueryParameterDiscovery, QueryParameterDiscovery>();
_services.AddScoped<ITargetedFields, TargetedFields>();
_services.AddScoped<IResourceDefinitionProvider, ResourceDefinitionProvider>();
Expand Down
26 changes: 13 additions & 13 deletions src/JsonApiDotNetCore/Builders/ResourceGraphBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace JsonApiDotNetCore.Builders
{
public class ResourceGraphBuilder : IResourceGraphBuilder
{
private readonly List<ContextEntity> _entities = new List<ContextEntity>();
private readonly List<ResourceContext> _entities = new List<ResourceContext>();
private readonly List<ValidationResult> _validationResults = new List<ValidationResult>();
private readonly IResourceNameFormatter _resourceNameFormatter = new KebabCaseFormatter();

Expand All @@ -36,9 +36,9 @@ public IResourceGraph Build()
return resourceGraph;
}

private void SetResourceLinksOptions(ContextEntity resourceContext)
private void SetResourceLinksOptions(ResourceContext resourceContext)
{
var attribute = (LinksAttribute)resourceContext.EntityType.GetCustomAttribute(typeof(LinksAttribute));
var attribute = (LinksAttribute)resourceContext.ResourceType.GetCustomAttribute(typeof(LinksAttribute));
if (attribute != null)
{
resourceContext.RelationshipLinks = attribute.RelationshipLinks;
Expand Down Expand Up @@ -67,14 +67,14 @@ public IResourceGraphBuilder AddResource(Type entityType, Type idType, string pl
return this;
}

private ContextEntity GetEntity(string pluralizedTypeName, Type entityType, Type idType) => new ContextEntity
private ResourceContext GetEntity(string pluralizedTypeName, Type entityType, Type idType) => new ResourceContext
{
EntityName = pluralizedTypeName,
EntityType = entityType,
ResourceName = pluralizedTypeName,
ResourceType = entityType,
IdentityType = idType,
Attributes = GetAttributes(entityType),
Relationships = GetRelationships(entityType),
ResourceType = GetResourceDefinitionType(entityType)
ResourceDefinitionType = GetResourceDefinitionType(entityType)
};


Expand Down Expand Up @@ -125,8 +125,8 @@ protected virtual List<RelationshipAttribute> GetRelationships(Type entityType)

attribute.PublicRelationshipName = attribute.PublicRelationshipName ?? _resourceNameFormatter.FormatPropertyName(prop);
attribute.InternalRelationshipName = prop.Name;
attribute.DependentType = GetRelationshipType(attribute, prop);
attribute.PrincipalType = entityType;
attribute.RightType = GetRelationshipType(attribute, prop);
attribute.LeftType = entityType;
attributes.Add(attribute);

if (attribute is HasManyThroughAttribute hasManyThroughAttribute)
Expand Down Expand Up @@ -160,13 +160,13 @@ protected virtual List<RelationshipAttribute> GetRelationships(Type entityType)
?? throw new JsonApiSetupException($"{hasManyThroughAttribute.ThroughType} does not contain a relationship id property to type {entityType} with name {leftIdPropertyName}");

// Article → ArticleTag.Tag
hasManyThroughAttribute.RightProperty = throughProperties.SingleOrDefault(x => x.PropertyType == hasManyThroughAttribute.DependentType)
?? throw new JsonApiSetupException($"{hasManyThroughAttribute.ThroughType} does not contain a navigation property to type {hasManyThroughAttribute.DependentType}");
hasManyThroughAttribute.RightProperty = throughProperties.SingleOrDefault(x => x.PropertyType == hasManyThroughAttribute.RightType)
?? throw new JsonApiSetupException($"{hasManyThroughAttribute.ThroughType} does not contain a navigation property to type {hasManyThroughAttribute.RightType}");

// ArticleTag.TagId
var rightIdPropertyName = JsonApiOptions.RelatedIdMapper.GetRelatedIdPropertyName(hasManyThroughAttribute.RightProperty.Name);
hasManyThroughAttribute.RightIdProperty = throughProperties.SingleOrDefault(x => x.Name == rightIdPropertyName)
?? throw new JsonApiSetupException($"{hasManyThroughAttribute.ThroughType} does not contain a relationship id property to type {hasManyThroughAttribute.DependentType} with name {rightIdPropertyName}");
?? throw new JsonApiSetupException($"{hasManyThroughAttribute.ThroughType} does not contain a relationship id property to type {hasManyThroughAttribute.RightType} with name {rightIdPropertyName}");
}
}

Expand Down Expand Up @@ -234,7 +234,7 @@ private string GetResourceNameFromDbSetProperty(PropertyInfo property, Type reso

private void AssertEntityIsNotAlreadyDefined(Type entityType)
{
if (_entities.Any(e => e.EntityType == entityType))
if (_entities.Any(e => e.ResourceType == entityType))
throw new InvalidOperationException($"Cannot add entity type {entityType} to context resourceGraph, there is already an entity of that type configured.");
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/JsonApiDotNetCore/Configuration/IJsonApiOptions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using JsonApiDotNetCore.Internal.Contracts;

namespace JsonApiDotNetCore.Configuration
{
public interface IJsonApiOptions : ILinksConfiguration, ISerializerOptions
Expand Down
1 change: 0 additions & 1 deletion src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using JsonApiDotNetCore.Builders;
using JsonApiDotNetCore.Graph;
using JsonApiDotNetCore.Models;
using JsonApiDotNetCore.Models.Links;
Expand Down
13 changes: 2 additions & 11 deletions src/JsonApiDotNetCore/Controllers/BaseJsonApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Extensions;
using JsonApiDotNetCore.Internal;
using JsonApiDotNetCore.Internal.Contracts;
using JsonApiDotNetCore.Models;
using JsonApiDotNetCore.Services;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -32,14 +31,11 @@ public BaseJsonApiController(
IResourceService<T, TId> resourceService,
ILoggerFactory loggerFactory)
{
if(loggerFactory != null)
{
if (loggerFactory != null)
_logger = loggerFactory.CreateLogger<BaseJsonApiController<T, TId>>();
}
else
{
_logger = new Logger<BaseJsonApiController<T, TId>>(new LoggerFactory());
}

_jsonApiOptions = jsonApiOptions;
_getAll = resourceService;
_getById = resourceService;
Expand All @@ -51,7 +47,6 @@ public BaseJsonApiController(
_delete = resourceService;
}


public BaseJsonApiController(
IJsonApiOptions jsonApiOptions,
IResourceQueryService<T, TId> queryService = null,
Expand All @@ -68,11 +63,7 @@ public BaseJsonApiController(
_delete = cmdService;
}

/// <summary>
/// Base constructor
/// </summary>
/// <param name="jsonApiOptions"></param>
/// <param name="resourceGraph"></param>
/// <param name="getAll"></param>
/// <param name="getById"></param>
/// <param name="getRelationship"></param>
Expand Down
1 change: 0 additions & 1 deletion src/JsonApiDotNetCore/Controllers/JsonApiCmdController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Models;
Expand Down
Loading