예제 #1
0
 public DefaultResourceService(
     IFieldsToSerialize fieldsToSerialize,
     IEnumerable <IQueryParameterService> queryParameters,
     IJsonApiOptions options,
     ILoggerFactory loggerFactory,
     IResourceRepository <TResource, TId> repository,
     IResourceContextProvider provider,
     IResourceChangeTracker <TResource> resourceChangeTracker,
     IResourceFactory resourceFactory,
     IResourceHookExecutor hookExecutor = null)
 {
     _fieldsToSerialize   = fieldsToSerialize;
     _includeService      = queryParameters.FirstOrDefault <IIncludeService>();
     _sparseFieldsService = queryParameters.FirstOrDefault <ISparseFieldsService>();
     _pageService         = queryParameters.FirstOrDefault <IPageService>();
     _sortService         = queryParameters.FirstOrDefault <ISortService>();
     _filterService       = queryParameters.FirstOrDefault <IFilterService>();
     _options             = options;
     _logger                 = loggerFactory.CreateLogger <DefaultResourceService <TResource, TId> >();
     _repository             = repository;
     _resourceChangeTracker  = resourceChangeTracker;
     _resourceFactory        = resourceFactory;
     _hookExecutor           = hookExecutor;
     _currentRequestResource = provider.GetResourceContext <TResource>();
 }
 public IncludedResourceObjectBuilder(IFieldsToSerialize fieldsToSerialize,
                                      ILinkBuilder linkBuilder,
                                      IResourceContextProvider resourceContextProvider,
                                      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));
 }
 public IncludedResourceObjectBuilder(IFieldsToSerialize fieldsToSerialize,
                                      ILinkBuilder linkBuilder,
                                      IResourceContextProvider provider,
                                      IResourceObjectBuilderSettingsProvider settingsProvider)
     : base(provider, settingsProvider.Get())
 {
     _included          = new HashSet <ResourceObject>(new ResourceObjectComparer());
     _fieldsToSerialize = fieldsToSerialize;
     _linkBuilder       = linkBuilder;
 }
예제 #4
0
        private IncludedResourceObjectBuilder GetBuilder()
        {
            IFieldsToSerialize fields = GetSerializableFields();
            ILinkBuilder       links  = GetLinkBuilder();

            IResourceDefinitionAccessor accessor = new Mock <IResourceDefinitionAccessor>().Object;

            return(new IncludedResourceObjectBuilder(fields, links, ResourceGraph, Enumerable.Empty <IQueryConstraintProvider>(), accessor,
                                                     GetSerializerSettingsProvider()));
        }
예제 #5
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));
 }
예제 #6
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));
        }
예제 #7
0
 public ResponseSerializer(IMetaBuilder <TResource> metaBuilder,
                           ILinkBuilder linkBuilder,
                           IIncludedResourceObjectBuilder includedBuilder,
                           IFieldsToSerialize fieldsToSerialize,
                           IResourceObjectBuilder resourceObjectBuilder) :
     base(resourceObjectBuilder)
 {
     _fieldsToSerialize   = fieldsToSerialize;
     _linkBuilder         = linkBuilder;
     _metaBuilder         = metaBuilder;
     _includedBuilder     = includedBuilder;
     _primaryResourceType = typeof(TResource);
 }
 public IncludedResourceObjectBuilder(IFieldsToSerialize fieldsToSerialize,
                                      ILinkBuilder linkBuilder,
                                      IResourceContextProvider resourceContextProvider,
                                      IEnumerable <IQueryConstraintProvider> constraintProviders,
                                      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));
     _sparseFieldSetCache        = new SparseFieldSetCache(constraintProviders, resourceDefinitionAccessor);
 }
예제 #9
0
        public JsonApiSerializerBenchmarks()
        {
            IResourceGraph     resourceGraph     = DependencyFactory.CreateResourceGraph();
            IFieldsToSerialize fieldsToSerialize = CreateFieldsToSerialize(resourceGraph);

            var metaBuilderMock    = new Mock <IMetaBuilder <BenchmarkResource> >();
            var linkBuilderMock    = new Mock <ILinkBuilder>();
            var includeBuilderMock = new Mock <IIncludedResourceObjectBuilder>();

            var resourceObjectBuilder = new ResourceObjectBuilder(resourceGraph, new ResourceObjectBuilderSettings());

            _jsonApiSerializer = new ResponseSerializer <BenchmarkResource>(metaBuilderMock.Object, linkBuilderMock.Object,
                                                                            includeBuilderMock.Object, fieldsToSerialize, resourceObjectBuilder);
        }
 public ResponseResourceObjectBuilder(IFieldsToSerialize fieldsToSerialize,
                                      ILinkBuilder linkBuilder,
                                      IIncludedResourceObjectBuilder includedBuilder,
                                      IIncludeService includeService,
                                      IResourceContextProvider provider,
                                      IResourceObjectBuilderSettingsProvider settingsProvider,
                                      ILoggerFactory loggerFactory)
     : base(provider, settingsProvider.Get())
 {
     _logger            = loggerFactory.CreateLogger <ResponseResourceObjectBuilder>();
     _linkBuilder       = linkBuilder;
     _includedBuilder   = includedBuilder;
     _includeService    = includeService;
     _fieldsToSerialize = fieldsToSerialize;
 }
        public JsonApiSerializerBenchmarks()
        {
            var                options           = new JsonApiOptions();
            IResourceGraph     resourceGraph     = _dependencyFactory.CreateResourceGraph(options);
            IFieldsToSerialize fieldsToSerialize = CreateFieldsToSerialize(resourceGraph);

            IMetaBuilder metaBuilder = new Mock <IMetaBuilder>().Object;
            ILinkBuilder linkBuilder = new Mock <ILinkBuilder>().Object;
            IIncludedResourceObjectBuilder includeBuilder = new Mock <IIncludedResourceObjectBuilder>().Object;

            var resourceObjectBuilder = new ResourceObjectBuilder(resourceGraph, new ResourceObjectBuilderSettings());

            _jsonApiSerializer = new ResponseSerializer <BenchmarkResource>(metaBuilder, linkBuilder,
                                                                            includeBuilder, fieldsToSerialize, resourceObjectBuilder, options);
        }
 public ResponseSerializer(IMetaBuilder metaBuilder,
                           ILinkBuilder linkBuilder,
                           IIncludedResourceObjectBuilder includedBuilder,
                           IFieldsToSerialize fieldsToSerialize,
                           IResourceObjectBuilder resourceObjectBuilder,
                           IJsonApiOptions options)
     : base(resourceObjectBuilder)
 {
     _fieldsToSerialize   = fieldsToSerialize ?? throw new ArgumentNullException(nameof(fieldsToSerialize));
     _options             = options ?? throw new ArgumentNullException(nameof(options));
     _linkBuilder         = linkBuilder ?? throw new ArgumentNullException(nameof(linkBuilder));
     _metaBuilder         = metaBuilder ?? throw new ArgumentNullException(nameof(metaBuilder));
     _includedBuilder     = includedBuilder ?? throw new ArgumentNullException(nameof(includedBuilder));
     _primaryResourceType = typeof(TResource);
 }
        public AtomicOperationsResponseSerializer(IResourceObjectBuilder resourceObjectBuilder, IMetaBuilder metaBuilder, ILinkBuilder linkBuilder,
                                                  IFieldsToSerialize fieldsToSerialize, IJsonApiRequest request, IJsonApiOptions options)
            : base(resourceObjectBuilder)
        {
            ArgumentGuard.NotNull(metaBuilder, nameof(metaBuilder));
            ArgumentGuard.NotNull(linkBuilder, nameof(linkBuilder));
            ArgumentGuard.NotNull(fieldsToSerialize, nameof(fieldsToSerialize));
            ArgumentGuard.NotNull(request, nameof(request));
            ArgumentGuard.NotNull(options, nameof(options));

            _metaBuilder       = metaBuilder;
            _linkBuilder       = linkBuilder;
            _fieldsToSerialize = fieldsToSerialize;
            _request           = request;
            _options           = options;
        }
        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();

            var resourceObjectBuilder = new ResponseResourceObjectBuilder(link, includedBuilder, includeConstraints, ResourceGraph,
                                                                          GetResourceDefinitionAccessor(), GetSerializerSettingsProvider());

            return(new ResponseSerializer <T>(meta, link, includedBuilder, fieldsToSerialize, resourceObjectBuilder, new JsonApiOptions()));
        }
        public ResponseSerializer(IMetaBuilder metaBuilder, ILinkBuilder linkBuilder, IIncludedResourceObjectBuilder includedBuilder,
                                  IFieldsToSerialize fieldsToSerialize, IResourceObjectBuilder resourceObjectBuilder, 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(options, nameof(options));

            _metaBuilder         = metaBuilder;
            _linkBuilder         = linkBuilder;
            _includedBuilder     = includedBuilder;
            _fieldsToSerialize   = fieldsToSerialize;
            _options             = options;
            _primaryResourceType = typeof(TResource);
        }
        public IncludedResourceObjectBuilder(IFieldsToSerialize fieldsToSerialize, ILinkBuilder linkBuilder, IResourceContextProvider resourceContextProvider,
                                             IEnumerable <IQueryConstraintProvider> constraintProviders, IResourceDefinitionAccessor resourceDefinitionAccessor,
                                             IRequestQueryStringAccessor queryStringAccessor, 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));
            ArgumentGuard.NotNull(queryStringAccessor, nameof(queryStringAccessor));

            _included                   = new HashSet <ResourceObject>(ResourceIdentifierObjectComparer.Instance);
            _fieldsToSerialize          = fieldsToSerialize;
            _linkBuilder                = linkBuilder;
            _resourceDefinitionAccessor = resourceDefinitionAccessor;
            _queryStringAccessor        = queryStringAccessor;
            _sparseFieldSetCache        = new SparseFieldSetCache(constraintProviders, resourceDefinitionAccessor);
        }
        public AtomicOperationsResponseSerializer(IResourceObjectBuilder resourceObjectBuilder, IMetaBuilder metaBuilder, ILinkBuilder linkBuilder,
                                                  IFieldsToSerialize fieldsToSerialize, IResourceDefinitionAccessor resourceDefinitionAccessor, IEvaluatedIncludeCache evaluatedIncludeCache,
                                                  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(evaluatedIncludeCache, nameof(evaluatedIncludeCache));
            ArgumentGuard.NotNull(request, nameof(request));
            ArgumentGuard.NotNull(options, nameof(options));

            _metaBuilder                = metaBuilder;
            _linkBuilder                = linkBuilder;
            _fieldsToSerialize          = fieldsToSerialize;
            _resourceDefinitionAccessor = resourceDefinitionAccessor;
            _evaluatedIncludeCache      = evaluatedIncludeCache;
            _request = request;
            _options = options;
        }