Skip to content

Consider simplifying constructor signatures in controller/repo/service layer #568

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
wisepotato opened this issue Oct 9, 2019 · 2 comments

Comments

@wisepotato
Copy link
Contributor

Its only needed here:

if (_jsonApiContext.Options.ValidateModelState && !ModelState.IsValid)
return UnprocessableEntity(ModelState.ConvertToErrorCollection<T>(_jsonApiContext.ResourceGraph));

So.. we might be able to get rid of that.

@maurei
Copy link
Member

maurei commented Oct 10, 2019

Controller layer

  • Remove ResourceGraph dependency in controller

Service layer

  • Consider having a wrapping service to decrease size of constructors, allowing for easier extensibility
  • Consider having internal constructors with signatures that allow for pipeline specific testing
  • Consider splitting into smaller classes, see source

Repo layer

@maurei maurei changed the title Remove ResourceGraph dependency in controller Consider simplifying constructor signatures in controller/repo/service layer Oct 10, 2019
@maurei
Copy link
Member

maurei commented Oct 22, 2019

We could consider to do something like this.

Instead of

        public DefaultResourceService(
                ISortService sortService,
                IFilterService filterService,
                IIncludeService includeService,
                ISparseFieldsService sparseFieldsService,
                IPageService pageManager,
                IJsonApiOptions options,
                IResourceRepository<TResource, TId> repository,
                IResourceContextProvider provider,
                IResourceHookExecutor hookExecutor = null,
                ILoggerFactory loggerFactory = null)
        {
            _includeService = includeService;
            _sparseFieldsService = sparseFieldsService;
            _pageManager = pageManager;
            _options = options;
            _sortService = sortService;
            _filterService = filterService;
            _repository = repository;
            _hookExecutor = hookExecutor;
            _logger = loggerFactory?.CreateLogger<DefaultResourceService<TResource, TId>>();
            _currentRequestResource = provider.GetResourceContext<TResource>();
        }

public DefaultResourceService(IEnumerable<IQueryParameterService> queryServices,  ....)

we could do

        public DefaultResourceService(
                IEnumerable<IQueryParameterService> queryParameters
                IJsonApiOptions options,
                IResourceRepository<TResource, TId> repository,
                IResourceContextProvider provider,
                IResourceHookExecutor hookExecutor = null,
                ILoggerFactory loggerFactory = null)
        {
            _includeService = queryParameters.Single(qp => qp is IIncludedService);
            _sparseFieldsService =  queryParameters.Single(qp => qp is ISparseFieldsService);
            _pageManager =  queryParameters.Single(qp => qp is IPageService);
            _sortService =  queryParameters.Single(qp => qp is ISortService);
            _filterService =  queryParameters.Single(qp => qp is IFilterService);
            _repository = repository;
            _options = options;
            _hookExecutor = hookExecutor;
            _logger = loggerFactory?.CreateLogger<DefaultResourceService<TResource, TId>>();
            _currentRequestResource = provider.GetResourceContext<TResource>();
        }

This would allow for a more extensibility and future features without having to introduce breaking changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants