public JsonApiResourceService(
            IResourceRepository <TResource, TId> repository,
            IQueryLayerComposer queryLayerComposer,
            IPaginationContext paginationContext,
            IJsonApiOptions options,
            ILoggerFactory loggerFactory,
            IJsonApiRequest request,
            IResourceChangeTracker <TResource> resourceChangeTracker,
            IResourceFactory resourceFactory,
            IResourceHookExecutor hookExecutor = null)
        {
            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            _repository            = repository ?? throw new ArgumentNullException(nameof(repository));
            _queryLayerComposer    = queryLayerComposer ?? throw new ArgumentNullException(nameof(queryLayerComposer));
            _paginationContext     = paginationContext ?? throw new ArgumentNullException(nameof(paginationContext));
            _options               = options ?? throw new ArgumentNullException(nameof(options));
            _traceWriter           = new TraceLogWriter <JsonApiResourceService <TResource, TId> >(loggerFactory);
            _request               = request ?? throw new ArgumentNullException(nameof(request));
            _resourceChangeTracker = resourceChangeTracker ?? throw new ArgumentNullException(nameof(resourceChangeTracker));
            _resourceFactory       = resourceFactory ?? throw new ArgumentNullException(nameof(resourceFactory));
            _hookExecutor          = hookExecutor;
        }
Example #2
0
        public JsonApiResourceService(IResourceRepositoryAccessor repositoryAccessor, IQueryLayerComposer queryLayerComposer,
                                      IPaginationContext paginationContext, IJsonApiOptions options, ILoggerFactory loggerFactory, IJsonApiRequest request,
                                      IResourceChangeTracker <TResource> resourceChangeTracker, IResourceHookExecutorFacade hookExecutor)
        {
            ArgumentGuard.NotNull(repositoryAccessor, nameof(repositoryAccessor));
            ArgumentGuard.NotNull(queryLayerComposer, nameof(queryLayerComposer));
            ArgumentGuard.NotNull(paginationContext, nameof(paginationContext));
            ArgumentGuard.NotNull(options, nameof(options));
            ArgumentGuard.NotNull(loggerFactory, nameof(loggerFactory));
            ArgumentGuard.NotNull(request, nameof(request));
            ArgumentGuard.NotNull(resourceChangeTracker, nameof(resourceChangeTracker));
            ArgumentGuard.NotNull(hookExecutor, nameof(hookExecutor));

            _repositoryAccessor    = repositoryAccessor;
            _queryLayerComposer    = queryLayerComposer;
            _paginationContext     = paginationContext;
            _options               = options;
            _request               = request;
            _resourceChangeTracker = resourceChangeTracker;
            _hookExecutor          = hookExecutor;
            _traceWriter           = new TraceLogWriter <JsonApiResourceService <TResource, TId> >(loggerFactory);

#pragma warning disable 612 // Method is obsolete
            _resourceDefinitionAccessor = queryLayerComposer.GetResourceDefinitionAccessor();
#pragma warning restore 612
        }
        public IncludeQueryStringParameterReader(IJsonApiRequest request, IResourceContextProvider resourceContextProvider, IJsonApiOptions options)
            : base(request, resourceContextProvider)
        {
            ArgumentGuard.NotNull(options, nameof(options));

            _options       = options;
            _includeParser = new IncludeParser(resourceContextProvider, ValidateSingleRelationship);
        }
Example #4
0
 public FilterQueryStringParameterReader(IJsonApiRequest request,
                                         IResourceContextProvider resourceContextProvider, IResourceFactory resourceFactory, IJsonApiOptions options)
     : base(request, resourceContextProvider)
 {
     _options      = options ?? throw new ArgumentNullException(nameof(options));
     _scopeParser  = new QueryStringParameterScopeParser(resourceContextProvider, FieldChainRequirements.EndsInToMany);
     _filterParser = new FilterParser(resourceContextProvider, resourceFactory, ValidateSingleField);
 }
        public ResponseSerializerFactory(IJsonApiRequest request, IRequestScopedServiceProvider provider)
        {
            ArgumentGuard.NotNull(request, nameof(request));
            ArgumentGuard.NotNull(provider, nameof(provider));

            _request  = request;
            _provider = provider;
        }
 public OperationContainer(OperationKind kind, IIdentifiable resource, ITargetedFields targetedFields,
                           IJsonApiRequest request)
 {
     Kind           = kind;
     Resource       = resource ?? throw new ArgumentNullException(nameof(resource));
     TargetedFields = targetedFields ?? throw new ArgumentNullException(nameof(targetedFields));
     Request        = request ?? throw new ArgumentNullException(nameof(request));
 }
 public TelevisionBroadcastDefinition(IResourceGraph resourceGraph, TelevisionDbContext dbContext, IJsonApiRequest request,
                                      IEnumerable <IQueryConstraintProvider> constraintProviders)
     : base(resourceGraph)
 {
     _dbContext           = dbContext;
     _request             = request;
     _constraintProviders = constraintProviders;
 }
Example #8
0
        public ResourceDefinitionQueryableParameterReader(IJsonApiRequest request, IResourceDefinitionAccessor resourceDefinitionAccessor)
        {
            ArgumentGuard.NotNull(request, nameof(request));
            ArgumentGuard.NotNull(resourceDefinitionAccessor, nameof(resourceDefinitionAccessor));

            _request = request;
            _resourceDefinitionAccessor = resourceDefinitionAccessor;
        }
        public async Task Invoke(HttpContext httpContext,
                                 IControllerResourceMapping controllerResourceMapping,
                                 IJsonApiOptions options,
                                 IJsonApiRequest request,
                                 IResourceContextProvider resourceContextProvider)
        {
            if (httpContext == null)
            {
                throw new ArgumentNullException(nameof(httpContext));
            }
            if (controllerResourceMapping == null)
            {
                throw new ArgumentNullException(nameof(controllerResourceMapping));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            if (resourceContextProvider == null)
            {
                throw new ArgumentNullException(nameof(resourceContextProvider));
            }

            var routeValues = httpContext.GetRouteData().Values;

            var primaryResourceContext = CreatePrimaryResourceContext(routeValues, controllerResourceMapping, resourceContextProvider);

            if (primaryResourceContext != null)
            {
                if (!await ValidateContentTypeHeaderAsync(HeaderConstants.MediaType, httpContext, options.SerializerSettings) ||
                    !await ValidateAcceptHeaderAsync(_mediaType, httpContext, options.SerializerSettings))
                {
                    return;
                }

                SetupResourceRequest((JsonApiRequest)request, primaryResourceContext, routeValues, options, resourceContextProvider, httpContext.Request);

                httpContext.RegisterJsonApiRequest();
            }
            else if (IsOperationsRequest(routeValues))
            {
                if (!await ValidateContentTypeHeaderAsync(HeaderConstants.AtomicOperationsMediaType, httpContext, options.SerializerSettings) ||
                    !await ValidateAcceptHeaderAsync(_atomicOperationsMediaType, httpContext, options.SerializerSettings))
                {
                    return;
                }

                SetupOperationsRequest((JsonApiRequest)request, options, httpContext.Request);

                httpContext.RegisterJsonApiRequest();
            }

            await _next(httpContext);
        }
        public FieldsToSerialize(IResourceContextProvider resourceContextProvider, IEnumerable <IQueryConstraintProvider> constraintProviders,
                                 IResourceDefinitionAccessor resourceDefinitionAccessor, IJsonApiRequest request)
        {
            ArgumentGuard.NotNull(resourceContextProvider, nameof(resourceContextProvider));
            ArgumentGuard.NotNull(request, nameof(request));

            _resourceContextProvider = resourceContextProvider;
            _request             = request;
            _sparseFieldSetCache = new SparseFieldSetCache(constraintProviders, resourceDefinitionAccessor);
        }
 public SoftDeletionAwareResourceService(ISystemClock systemClock, ITargetedFields targetedFields, IResourceRepositoryAccessor repositoryAccessor,
                                         IQueryLayerComposer queryLayerComposer, IPaginationContext paginationContext, IJsonApiOptions options, ILoggerFactory loggerFactory,
                                         IJsonApiRequest request, IResourceChangeTracker <TResource> resourceChangeTracker, IResourceHookExecutorFacade hookExecutor)
     : base(repositoryAccessor, queryLayerComposer, paginationContext, options, loggerFactory, request, resourceChangeTracker, hookExecutor)
 {
     _systemClock        = systemClock;
     _targetedFields     = targetedFields;
     _repositoryAccessor = repositoryAccessor;
     _request            = request;
 }
        public ResourceRepositoryAccessor(IServiceProvider serviceProvider, IResourceContextProvider resourceContextProvider, IJsonApiRequest request)
        {
            ArgumentGuard.NotNull(serviceProvider, nameof(serviceProvider));
            ArgumentGuard.NotNull(resourceContextProvider, nameof(resourceContextProvider));
            ArgumentGuard.NotNull(request, nameof(request));

            _serviceProvider         = serviceProvider;
            _resourceContextProvider = resourceContextProvider;
            _request = request;
        }
        protected QueryStringParameterReader(IJsonApiRequest request, IResourceContextProvider resourceContextProvider)
        {
            ArgumentGuard.NotNull(request, nameof(request));
            ArgumentGuard.NotNull(resourceContextProvider, nameof(resourceContextProvider));

            _resourceContextProvider  = resourceContextProvider;
            _isCollectionRequest      = request.IsCollection;
            RequestResource           = request.SecondaryResource ?? request.PrimaryResource;
            IsAtomicOperationsRequest = request.Kind == EndpointKind.AtomicOperations;
        }
Example #14
0
        protected QueryStringParameterReader(IJsonApiRequest request, IResourceContextProvider resourceContextProvider)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            _resourceContextProvider = resourceContextProvider ?? throw new ArgumentNullException(nameof(resourceContextProvider));
            _isCollectionRequest     = request.IsCollection;
            RequestResource          = request.SecondaryResource ?? request.PrimaryResource;
        }
Example #15
0
 public AtomicOperationsResponseSerializer(IResourceObjectBuilder resourceObjectBuilder,
                                           IMetaBuilder metaBuilder, ILinkBuilder linkBuilder, IFieldsToSerialize fieldsToSerialize,
                                           IJsonApiRequest request, IJsonApiOptions options)
     : base(resourceObjectBuilder)
 {
     _metaBuilder       = metaBuilder ?? throw new ArgumentNullException(nameof(metaBuilder));
     _linkBuilder       = linkBuilder ?? throw new ArgumentNullException(nameof(linkBuilder));
     _fieldsToSerialize = fieldsToSerialize ?? throw new ArgumentNullException(nameof(fieldsToSerialize));
     _request           = request ?? throw new ArgumentNullException(nameof(request));
     _options           = options ?? throw new ArgumentNullException(nameof(options));
 }
Example #16
0
        public OperationContainer(OperationKind kind, IIdentifiable resource, ITargetedFields targetedFields, IJsonApiRequest request)
        {
            ArgumentGuard.NotNull(resource, nameof(resource));
            ArgumentGuard.NotNull(targetedFields, nameof(targetedFields));
            ArgumentGuard.NotNull(request, nameof(request));

            Kind           = kind;
            Resource       = resource;
            TargetedFields = targetedFields;
            Request        = request;
        }
Example #17
0
 public FieldsToSerialize(
     IResourceGraph resourceGraph,
     IEnumerable <IQueryConstraintProvider> constraintProviders,
     IResourceDefinitionAccessor resourceDefinitionAccessor,
     IJsonApiRequest request)
 {
     _resourceGraph              = resourceGraph ?? throw new ArgumentNullException(nameof(resourceGraph));
     _constraintProviders        = constraintProviders ?? throw new ArgumentNullException(nameof(constraintProviders));
     _resourceDefinitionAccessor = resourceDefinitionAccessor ?? throw new ArgumentNullException(nameof(resourceDefinitionAccessor));
     _request = request ?? throw new ArgumentNullException(nameof(request));
 }
Example #18
0
 public LinkBuilder(IJsonApiOptions options,
                    IJsonApiRequest request,
                    IPaginationContext paginationContext,
                    IResourceContextProvider provider,
                    IRequestQueryStringAccessor queryStringAccessor)
 {
     _options             = options ?? throw new ArgumentNullException(nameof(options));
     _request             = request ?? throw new ArgumentNullException(nameof(request));
     _paginationContext   = paginationContext ?? throw new ArgumentNullException(nameof(paginationContext));
     _provider            = provider ?? throw new ArgumentNullException(nameof(provider));
     _queryStringAccessor = queryStringAccessor ?? throw new ArgumentNullException(nameof(queryStringAccessor));
 }
 public OperationsProcessor(IOperationProcessorAccessor operationProcessorAccessor,
                            IOperationsTransactionFactory operationsTransactionFactory, ILocalIdTracker localIdTracker,
                            IResourceContextProvider resourceContextProvider, IJsonApiRequest request, ITargetedFields targetedFields)
 {
     _operationProcessorAccessor   = operationProcessorAccessor ?? throw new ArgumentNullException(nameof(operationProcessorAccessor));
     _operationsTransactionFactory = operationsTransactionFactory ?? throw new ArgumentNullException(nameof(operationsTransactionFactory));
     _localIdTracker          = localIdTracker ?? throw new ArgumentNullException(nameof(localIdTracker));
     _resourceContextProvider = resourceContextProvider ?? throw new ArgumentNullException(nameof(resourceContextProvider));
     _request          = request ?? throw new ArgumentNullException(nameof(request));
     _targetedFields   = targetedFields ?? throw new ArgumentNullException(nameof(targetedFields));
     _localIdValidator = new LocalIdValidator(_localIdTracker, _resourceContextProvider);
 }
Example #20
0
 public RequestDeserializer(
     IResourceContextProvider resourceContextProvider,
     IResourceFactory resourceFactory,
     ITargetedFields targetedFields,
     IHttpContextAccessor httpContextAccessor,
     IJsonApiRequest request)
     : base(resourceContextProvider, resourceFactory)
 {
     _targetedFields      = targetedFields ?? throw new ArgumentNullException(nameof(targetedFields));
     _httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor));
     _request             = request ?? throw new ArgumentNullException(nameof(request));
 }
Example #21
0
        public JsonApiReader(IJsonApiDeserializer deserializer,
                             IJsonApiRequest request,
                             ILoggerFactory loggerFactory)
        {
            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            _deserializer = deserializer ?? throw new ArgumentNullException(nameof(deserializer));
            _request      = request ?? throw new ArgumentNullException(nameof(request));
            _traceWriter  = new TraceLogWriter <JsonApiReader>(loggerFactory);
        }
Example #22
0
        public JsonApiReader(IJsonApiDeserializer deserializer, IJsonApiRequest request, IResourceContextProvider resourceContextProvider,
                             ILoggerFactory loggerFactory)
        {
            ArgumentGuard.NotNull(deserializer, nameof(deserializer));
            ArgumentGuard.NotNull(request, nameof(request));
            ArgumentGuard.NotNull(resourceContextProvider, nameof(resourceContextProvider));
            ArgumentGuard.NotNull(loggerFactory, nameof(loggerFactory));

            _deserializer            = deserializer;
            _request                 = request;
            _resourceContextProvider = resourceContextProvider;
            _traceWriter             = new TraceLogWriter <JsonApiReader>(loggerFactory);
        }
        protected BaseJsonApiOperationsController(IJsonApiOptions options, ILoggerFactory loggerFactory,
                                                  IOperationsProcessor processor, IJsonApiRequest request, ITargetedFields targetedFields)
        {
            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            _options        = options ?? throw new ArgumentNullException(nameof(options));
            _processor      = processor ?? throw new ArgumentNullException(nameof(processor));
            _request        = request ?? throw new ArgumentNullException(nameof(request));
            _targetedFields = targetedFields ?? throw new ArgumentNullException(nameof(targetedFields));
            _traceWriter    = new TraceLogWriter <BaseJsonApiOperationsController>(loggerFactory);
        }
        public RequestDeserializer(IResourceContextProvider resourceContextProvider, IResourceFactory resourceFactory, ITargetedFields targetedFields,
                                   IHttpContextAccessor httpContextAccessor, IJsonApiRequest request, IJsonApiOptions options)
            : base(resourceContextProvider, resourceFactory)
        {
            ArgumentGuard.NotNull(targetedFields, nameof(targetedFields));
            ArgumentGuard.NotNull(httpContextAccessor, nameof(httpContextAccessor));
            ArgumentGuard.NotNull(request, nameof(request));
            ArgumentGuard.NotNull(options, nameof(options));

            _targetedFields      = targetedFields;
            _httpContextAccessor = httpContextAccessor;
            _request             = request;
            _options             = options;
        }
Example #25
0
        protected BaseJsonApiOperationsController(IJsonApiOptions options, ILoggerFactory loggerFactory, IOperationsProcessor processor,
                                                  IJsonApiRequest request, ITargetedFields targetedFields)
        {
            ArgumentGuard.NotNull(options, nameof(options));
            ArgumentGuard.NotNull(loggerFactory, nameof(loggerFactory));
            ArgumentGuard.NotNull(processor, nameof(processor));
            ArgumentGuard.NotNull(request, nameof(request));
            ArgumentGuard.NotNull(targetedFields, nameof(targetedFields));

            _options        = options;
            _processor      = processor;
            _request        = request;
            _targetedFields = targetedFields;
            _traceWriter    = new TraceLogWriter <BaseJsonApiOperationsController>(loggerFactory);
        }