Skip to content
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

Possible to use generic handler? #29

Open
sgashua opened this issue Jun 21, 2021 · 0 comments
Open

Possible to use generic handler? #29

sgashua opened this issue Jun 21, 2021 · 0 comments

Comments

@sgashua
Copy link

sgashua commented Jun 21, 2021

To prevent too much works to do from creating too many handlers classes, is it possible to use generic handler for all entities? Or not recommended to use generic handler?

From

public partial class CreateBrandCommand : IRequest<Result<int>>
    {
        public string Name { get; set; }
        public string Description { get; set; }
        public decimal Tax { get; set; }
    }
public class CreateBrandCommandHandler : IRequestHandler<CreateBrandCommand, Result<int>>
    {
        private readonly IBrandRepository _brandRepository;
        private readonly IMapper _mapper;
...

To this generic handler

public partial class CreateCommand<T> : T, IRequest<Result<int>> where T : class { } 
public class CreateCommandHandler : IRequestHandler<CreateCommand<T>, Result<int>>
{
      private readonly IBaseRepository<T> _repo;
...

But I cannot get generic handler working. How to get it working?

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

No branches or pull requests

1 participant