Beispiel #1
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 HideRelationshipsSparseFieldSetCache(IEnumerable <IQueryConstraintProvider> constraintProviders,
                                                IResourceDefinitionAccessor resourceDefinitionAccessor)
    {
        ArgumentGuard.NotNull(constraintProviders, nameof(constraintProviders));
        ArgumentGuard.NotNull(resourceDefinitionAccessor, nameof(resourceDefinitionAccessor));

        _innerCache = new SparseFieldSetCache(constraintProviders, resourceDefinitionAccessor);
    }
Beispiel #3
0
        public ResourceDefinitionQueryableParameterReader(IJsonApiRequest request, IResourceDefinitionAccessor resourceDefinitionAccessor)
        {
            ArgumentGuard.NotNull(request, nameof(request));
            ArgumentGuard.NotNull(resourceDefinitionAccessor, nameof(resourceDefinitionAccessor));

            _request = request;
            _resourceDefinitionAccessor = resourceDefinitionAccessor;
        }
Beispiel #4
0
        public SparseFieldSetCache(IEnumerable <IQueryConstraintProvider> constraintProviders, IResourceDefinitionAccessor resourceDefinitionAccessor)
        {
            ArgumentGuard.NotNull(constraintProviders, nameof(constraintProviders));
            ArgumentGuard.NotNull(resourceDefinitionAccessor, nameof(resourceDefinitionAccessor));

            _resourceDefinitionAccessor = resourceDefinitionAccessor;
            _lazySourceTable            = new Lazy <IDictionary <ResourceContext, HashSet <ResourceFieldAttribute> > >(() => BuildSourceTable(constraintProviders));
            _visitedTable = new Dictionary <ResourceContext, HashSet <ResourceFieldAttribute> >();
        }
 public FieldsToSerialize(
     IResourceGraph resourceGraph,
     IEnumerable <IQueryConstraintProvider> constraintProviders,
     IResourceDefinitionAccessor resourceDefinitionAccessor)
 {
     _resourceGraph              = resourceGraph ?? throw new ArgumentNullException(nameof(resourceGraph));
     _constraintProviders        = constraintProviders ?? throw new ArgumentNullException(nameof(constraintProviders));
     _resourceDefinitionAccessor = resourceDefinitionAccessor ?? throw new ArgumentNullException(nameof(resourceDefinitionAccessor));
 }
        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);
        }
Beispiel #7
0
 public FieldsToSerialize(
     IResourceContextProvider resourceContextProvider,
     IEnumerable <IQueryConstraintProvider> constraintProviders,
     IResourceDefinitionAccessor resourceDefinitionAccessor,
     IJsonApiRequest request)
 {
     _resourceContextProvider = resourceContextProvider ?? throw new ArgumentNullException(nameof(resourceContextProvider));
     _request             = request ?? throw new ArgumentNullException(nameof(request));
     _sparseFieldSetCache = new SparseFieldSetCache(constraintProviders, resourceDefinitionAccessor);
 }
Beispiel #8
0
        private IIncludedResourceObjectBuilder GetIncludedBuilder(bool hasIncludeQueryString)
        {
            IFieldsToSerialize                     fieldsToSerialize                     = GetSerializableFields();
            ILinkBuilder                           linkBuilder                           = GetLinkBuilder();
            IResourceDefinitionAccessor            resourceDefinitionAccessor            = GetResourceDefinitionAccessor();
            IRequestQueryStringAccessor            queryStringAccessor                   = new FakeRequestQueryStringAccessor(hasIncludeQueryString ? "include=" : null);
            IResourceObjectBuilderSettingsProvider resourceObjectBuilderSettingsProvider = GetSerializerSettingsProvider();

            return(new IncludedResourceObjectBuilder(fieldsToSerialize, linkBuilder, ResourceGraph, Enumerable.Empty <IQueryConstraintProvider>(),
                                                     resourceDefinitionAccessor, queryStringAccessor, resourceObjectBuilderSettingsProvider));
        }
        public SparseFieldSetCache(IEnumerable <IQueryConstraintProvider> constraintProviders, IResourceDefinitionAccessor resourceDefinitionAccessor)
        {
            if (constraintProviders == null)
            {
                throw new ArgumentNullException(nameof(constraintProviders));
            }
            _resourceDefinitionAccessor = resourceDefinitionAccessor ?? throw new ArgumentNullException(nameof(resourceDefinitionAccessor));

            _lazySourceTable = new Lazy <IDictionary <ResourceContext, HashSet <ResourceFieldAttribute> > >(() => BuildSourceTable(constraintProviders));
            _visitedTable    = new Dictionary <ResourceContext, HashSet <ResourceFieldAttribute> >();
        }
 public IncludedResourceObjectBuilder(IFieldsToSerialize fieldsToSerialize,
                                      ILinkBuilder linkBuilder,
                                      IResourceContextProvider resourceContextProvider,
                                      IResourceDefinitionAccessor resourceDefinitionAccessor,
                                      IResourceObjectBuilderSettingsProvider settingsProvider)
     : base(resourceContextProvider, settingsProvider.Get())
 {
     _included                   = new HashSet <ResourceObject>(ResourceIdentifierObjectComparer.Instance);
     _fieldsToSerialize          = fieldsToSerialize ?? throw new ArgumentNullException(nameof(fieldsToSerialize));
     _linkBuilder                = linkBuilder ?? throw new ArgumentNullException(nameof(linkBuilder));
     _resourceDefinitionAccessor = resourceDefinitionAccessor ?? throw new ArgumentNullException(nameof(resourceDefinitionAccessor));
 }
Beispiel #11
0
 public QueryLayerComposer(
     IEnumerable <IQueryConstraintProvider> constraintProviders,
     IResourceContextProvider resourceContextProvider,
     IResourceDefinitionAccessor resourceDefinitionAccessor,
     IJsonApiOptions options,
     IPaginationContext paginationContext)
 {
     _constraintProviders        = constraintProviders ?? throw new ArgumentNullException(nameof(constraintProviders));
     _resourceContextProvider    = resourceContextProvider ?? throw new ArgumentNullException(nameof(resourceContextProvider));
     _resourceDefinitionAccessor = resourceDefinitionAccessor ?? throw new ArgumentNullException(nameof(resourceDefinitionAccessor));
     _options           = options ?? throw new ArgumentNullException(nameof(options));
     _paginationContext = paginationContext ?? throw new ArgumentNullException(nameof(paginationContext));
 }
 public ResponseResourceObjectBuilder(ILinkBuilder linkBuilder,
                                      IIncludedResourceObjectBuilder includedBuilder,
                                      IEnumerable <IQueryConstraintProvider> constraintProviders,
                                      IResourceContextProvider resourceContextProvider,
                                      IResourceDefinitionAccessor resourceDefinitionAccessor,
                                      IResourceObjectBuilderSettingsProvider settingsProvider)
     : base(resourceContextProvider, settingsProvider.Get())
 {
     _linkBuilder                = linkBuilder ?? throw new ArgumentNullException(nameof(linkBuilder));
     _includedBuilder            = includedBuilder ?? throw new ArgumentNullException(nameof(includedBuilder));
     _constraintProviders        = constraintProviders ?? throw new ArgumentNullException(nameof(constraintProviders));
     _resourceDefinitionAccessor = resourceDefinitionAccessor ?? throw new ArgumentNullException(nameof(resourceDefinitionAccessor));
 }
        public IncludedResourceObjectBuilder(IFieldsToSerialize fieldsToSerialize, ILinkBuilder linkBuilder, IResourceContextProvider resourceContextProvider,
                                             IEnumerable <IQueryConstraintProvider> constraintProviders, IResourceDefinitionAccessor resourceDefinitionAccessor,
                                             IResourceObjectBuilderSettingsProvider settingsProvider)
            : base(resourceContextProvider, settingsProvider.Get())
        {
            ArgumentGuard.NotNull(fieldsToSerialize, nameof(fieldsToSerialize));
            ArgumentGuard.NotNull(linkBuilder, nameof(linkBuilder));
            ArgumentGuard.NotNull(constraintProviders, nameof(constraintProviders));
            ArgumentGuard.NotNull(resourceDefinitionAccessor, nameof(resourceDefinitionAccessor));

            _included                   = new HashSet <ResourceObject>(ResourceIdentifierObjectComparer.Instance);
            _fieldsToSerialize          = fieldsToSerialize;
            _linkBuilder                = linkBuilder;
            _resourceDefinitionAccessor = resourceDefinitionAccessor;
            _sparseFieldSetCache        = new SparseFieldSetCache(constraintProviders, resourceDefinitionAccessor);
        }
 public QueryLayerComposer(
     IEnumerable <IQueryConstraintProvider> constraintProviders,
     IResourceContextProvider resourceContextProvider,
     IResourceDefinitionAccessor resourceDefinitionAccessor,
     IJsonApiOptions options,
     IPaginationContext paginationContext,
     ITargetedFields targetedFields)
 {
     _constraintProviders        = constraintProviders ?? throw new ArgumentNullException(nameof(constraintProviders));
     _resourceContextProvider    = resourceContextProvider ?? throw new ArgumentNullException(nameof(resourceContextProvider));
     _resourceDefinitionAccessor = resourceDefinitionAccessor ?? throw new ArgumentNullException(nameof(resourceDefinitionAccessor));
     _options             = options ?? throw new ArgumentNullException(nameof(options));
     _paginationContext   = paginationContext ?? throw new ArgumentNullException(nameof(paginationContext));
     _targetedFields      = targetedFields ?? throw new ArgumentNullException(nameof(targetedFields));
     _sparseFieldSetCache = new SparseFieldSetCache(constraintProviders, resourceDefinitionAccessor);
 }
        public ResponseResourceObjectBuilder(ILinkBuilder linkBuilder, IIncludedResourceObjectBuilder includedBuilder,
                                             IEnumerable <IQueryConstraintProvider> constraintProviders, IResourceContextProvider resourceContextProvider,
                                             IResourceDefinitionAccessor resourceDefinitionAccessor, IResourceObjectBuilderSettingsProvider settingsProvider)
            : base(resourceContextProvider, settingsProvider.Get())
        {
            ArgumentGuard.NotNull(linkBuilder, nameof(linkBuilder));
            ArgumentGuard.NotNull(includedBuilder, nameof(includedBuilder));
            ArgumentGuard.NotNull(constraintProviders, nameof(constraintProviders));
            ArgumentGuard.NotNull(resourceDefinitionAccessor, nameof(resourceDefinitionAccessor));

            _linkBuilder                = linkBuilder;
            _includedBuilder            = includedBuilder;
            _constraintProviders        = constraintProviders;
            _resourceDefinitionAccessor = resourceDefinitionAccessor;
            _sparseFieldSetCache        = new SparseFieldSetCache(_constraintProviders, resourceDefinitionAccessor);
        }
        public AtomicOperationsResponseSerializer(IResourceObjectBuilder resourceObjectBuilder, IMetaBuilder metaBuilder, ILinkBuilder linkBuilder,
                                                  IFieldsToSerialize fieldsToSerialize, IResourceDefinitionAccessor resourceDefinitionAccessor, IJsonApiRequest request, IJsonApiOptions options)
            : base(resourceObjectBuilder)
        {
            ArgumentGuard.NotNull(metaBuilder, nameof(metaBuilder));
            ArgumentGuard.NotNull(linkBuilder, nameof(linkBuilder));
            ArgumentGuard.NotNull(fieldsToSerialize, nameof(fieldsToSerialize));
            ArgumentGuard.NotNull(resourceDefinitionAccessor, nameof(resourceDefinitionAccessor));
            ArgumentGuard.NotNull(request, nameof(request));
            ArgumentGuard.NotNull(options, nameof(options));

            _metaBuilder                = metaBuilder;
            _linkBuilder                = linkBuilder;
            _fieldsToSerialize          = fieldsToSerialize;
            _resourceDefinitionAccessor = resourceDefinitionAccessor;
            _request = request;
            _options = options;
        }
Beispiel #17
0
        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;

#pragma warning disable 612 // Method is obsolete
            _resourceDefinitionAccessor = resourceFactory.GetResourceDefinitionAccessor();
#pragma warning restore 612
        }
Beispiel #18
0
        public QueryLayerComposer(IEnumerable <IQueryConstraintProvider> constraintProviders, IResourceContextProvider resourceContextProvider,
                                  IResourceDefinitionAccessor resourceDefinitionAccessor, IJsonApiOptions options, IPaginationContext paginationContext,
                                  ITargetedFields targetedFields)
        {
            ArgumentGuard.NotNull(constraintProviders, nameof(constraintProviders));
            ArgumentGuard.NotNull(resourceContextProvider, nameof(resourceContextProvider));
            ArgumentGuard.NotNull(resourceDefinitionAccessor, nameof(resourceDefinitionAccessor));
            ArgumentGuard.NotNull(options, nameof(options));
            ArgumentGuard.NotNull(paginationContext, nameof(paginationContext));
            ArgumentGuard.NotNull(targetedFields, nameof(targetedFields));

            _constraintProviders        = constraintProviders;
            _resourceContextProvider    = resourceContextProvider;
            _resourceDefinitionAccessor = resourceDefinitionAccessor;
            _options             = options;
            _paginationContext   = paginationContext;
            _targetedFields      = targetedFields;
            _sparseFieldSetCache = new SparseFieldSetCache(_constraintProviders, resourceDefinitionAccessor);
        }
        public ResponseSerializer(IMetaBuilder metaBuilder, ILinkBuilder linkBuilder, IIncludedResourceObjectBuilder includedBuilder,
                                  IFieldsToSerialize fieldsToSerialize, IResourceObjectBuilder resourceObjectBuilder, IResourceDefinitionAccessor resourceDefinitionAccessor,
                                  IJsonApiOptions options)
            : base(resourceObjectBuilder)
        {
            ArgumentGuard.NotNull(metaBuilder, nameof(metaBuilder));
            ArgumentGuard.NotNull(linkBuilder, nameof(linkBuilder));
            ArgumentGuard.NotNull(includedBuilder, nameof(includedBuilder));
            ArgumentGuard.NotNull(fieldsToSerialize, nameof(fieldsToSerialize));
            ArgumentGuard.NotNull(resourceDefinitionAccessor, nameof(resourceDefinitionAccessor));
            ArgumentGuard.NotNull(options, nameof(options));

            _metaBuilder                = metaBuilder;
            _linkBuilder                = linkBuilder;
            _includedBuilder            = includedBuilder;
            _fieldsToSerialize          = fieldsToSerialize;
            _resourceDefinitionAccessor = resourceDefinitionAccessor;
            _options             = options;
            _primaryResourceType = typeof(TResource);
        }
Beispiel #20
0
        public EntityFrameworkCoreRepository(ITargetedFields targetedFields, IDbContextResolver contextResolver, IResourceGraph resourceGraph,
                                             IResourceFactory resourceFactory, IEnumerable <IQueryConstraintProvider> constraintProviders, ILoggerFactory loggerFactory)
        {
            ArgumentGuard.NotNull(contextResolver, nameof(contextResolver));
            ArgumentGuard.NotNull(loggerFactory, nameof(loggerFactory));
            ArgumentGuard.NotNull(targetedFields, nameof(targetedFields));
            ArgumentGuard.NotNull(resourceGraph, nameof(resourceGraph));
            ArgumentGuard.NotNull(resourceFactory, nameof(resourceFactory));
            ArgumentGuard.NotNull(constraintProviders, nameof(constraintProviders));

            _targetedFields      = targetedFields;
            _resourceGraph       = resourceGraph;
            _resourceFactory     = resourceFactory;
            _constraintProviders = constraintProviders;
            _dbContext           = contextResolver.GetContext();
            _traceWriter         = new TraceLogWriter <EntityFrameworkCoreRepository <TResource, TId> >(loggerFactory);

#pragma warning disable 612 // Method is obsolete
            _resourceDefinitionAccessor = resourceFactory.GetResourceDefinitionAccessor();
#pragma warning restore 612
        }
    public MongoRepository(IMongoDataAccess mongoDataAccess, ITargetedFields targetedFields, IResourceGraph resourceGraph, IResourceFactory resourceFactory,
                           IEnumerable <IQueryConstraintProvider> constraintProviders, IResourceDefinitionAccessor resourceDefinitionAccessor)
    {
        ArgumentGuard.NotNull(mongoDataAccess, nameof(mongoDataAccess));
        ArgumentGuard.NotNull(targetedFields, nameof(targetedFields));
        ArgumentGuard.NotNull(resourceGraph, nameof(resourceGraph));
        ArgumentGuard.NotNull(resourceFactory, nameof(resourceFactory));
        ArgumentGuard.NotNull(constraintProviders, nameof(constraintProviders));
        ArgumentGuard.NotNull(resourceDefinitionAccessor, nameof(resourceDefinitionAccessor));

        _mongoDataAccess            = mongoDataAccess;
        _targetedFields             = targetedFields;
        _resourceGraph              = resourceGraph;
        _resourceFactory            = resourceFactory;
        _constraintProviders        = constraintProviders;
        _resourceDefinitionAccessor = resourceDefinitionAccessor;

        if (!typeof(TResource).IsAssignableTo(typeof(IMongoIdentifiable)))
        {
            throw new InvalidConfigurationException("MongoDB can only be used with resources that implement 'IMongoIdentifiable'.");
        }
    }
        protected ResponseSerializer <T> GetResponseSerializer <T>(IEnumerable <IEnumerable <RelationshipAttribute> > inclusionChains = null,
                                                                   Dictionary <string, object> metaDict = null, TopLevelLinks topLinks = null, ResourceLinks resourceLinks = null,
                                                                   RelationshipLinks relationshipLinks  = null)
            where T : class, IIdentifiable
        {
            IMetaBuilder meta = GetMetaBuilder(metaDict);
            ILinkBuilder link = GetLinkBuilder(topLinks, resourceLinks, relationshipLinks);
            IEnumerable <IQueryConstraintProvider> includeConstraints = GetIncludeConstraints(inclusionChains);
            IIncludedResourceObjectBuilder         includedBuilder    = GetIncludedBuilder();
            IFieldsToSerialize fieldsToSerialize = GetSerializableFields();

            IResourceDefinitionAccessor resourceDefinitionAccessor = GetResourceDefinitionAccessor();

            IResourceObjectBuilderSettingsProvider settingsProvider = GetSerializerSettingsProvider();

            var resourceObjectBuilder = new ResponseResourceObjectBuilder(link, includedBuilder, includeConstraints, ResourceGraph, resourceDefinitionAccessor,
                                                                          settingsProvider);

            var jsonApiOptions = new JsonApiOptions();

            return(new ResponseSerializer <T>(meta, link, includedBuilder, fieldsToSerialize, resourceObjectBuilder, resourceDefinitionAccessor, jsonApiOptions));
        }
 public ResourceDefinitionQueryableParameterReader(IJsonApiRequest request, IResourceDefinitionAccessor resourceDefinitionAccessor)
 {
     _request = request ?? throw new ArgumentNullException(nameof(request));
     _resourceDefinitionAccessor = resourceDefinitionAccessor ?? throw new ArgumentNullException(nameof(resourceDefinitionAccessor));
 }
Beispiel #24
0
 public ResultCapturingRepository(IMongoDataAccess mongoDataAccess, ITargetedFields targetedFields, IResourceGraph resourceGraph,
                                  IResourceFactory resourceFactory, IEnumerable <IQueryConstraintProvider> constraintProviders, IResourceDefinitionAccessor resourceDefinitionAccessor,
                                  ResourceCaptureStore captureStore)
     : base(mongoDataAccess, targetedFields, resourceGraph, resourceFactory, constraintProviders, resourceDefinitionAccessor)
 {
     _captureStore = captureStore;
 }
Beispiel #25
0
 public IgnoreRelationshipsResponseResourceObjectBuilder(ILinkBuilder linkBuilder,
                                                         IIncludedResourceObjectBuilder includedBuilder, IEnumerable <IQueryConstraintProvider> constraintProviders,
                                                         IResourceContextProvider resourceContextProvider, IResourceDefinitionAccessor resourceDefinitionAccessor,
                                                         IResourceObjectBuilderSettingsProvider settingsProvider)
     : base(linkBuilder, includedBuilder, constraintProviders, resourceContextProvider,
            resourceDefinitionAccessor, settingsProvider)
 {
 }
Beispiel #26
0
 public MusicTrackRepository(IMongoDataAccess mongoDataAccess, ITargetedFields targetedFields, IResourceGraph resourceGraph,
                             IResourceFactory resourceFactory, IEnumerable <IQueryConstraintProvider> constraintProviders, IResourceDefinitionAccessor resourceDefinitionAccessor)
     : base(mongoDataAccess, targetedFields, resourceGraph, resourceFactory, constraintProviders, resourceDefinitionAccessor)
 {
 }
        public LyricRepository(IMongoDataAccess mongoDataAccess, ITargetedFields targetedFields, IResourceGraph resourceGraph, IResourceFactory resourceFactory,
                               IEnumerable <IQueryConstraintProvider> constraintProviders, IResourceDefinitionAccessor resourceDefinitionAccessor)
            : base(mongoDataAccess, targetedFields, resourceGraph, resourceFactory, constraintProviders, resourceDefinitionAccessor)
        {
            IMongoDataAccess otherDataAccess = new MongoDataAccess(mongoDataAccess.MongoDatabase);

            var factory = new MongoTransactionFactory(otherDataAccess);

            _transaction = factory.BeginTransactionAsync(CancellationToken.None).Result;
        }