Razali

Untitled

Sep 24th, 2020 (edited)
826
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using MediatR;
  2. using System;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5.  
  6. namespace CA.Application.CompanyContext.Queries.DummyQuery
  7. {
  8.     public class DummyRequest_1 : IRequest<bool>{ }
  9.     public class DummyRequest_2 : IRequest<string> { }
  10.  
  11.     public abstract class AbstractDummyQueryHandler<TRequest, TResponse>
  12.         : IRequestHandler<TRequest, TResponse>
  13.         where TRequest : IRequest<TResponse>
  14.     {
  15.         public Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken)
  16.         {
  17.             //same code stuffs here
  18.             //same code stuffs here
  19.             //same code stuffs here
  20.             //same code stuffs here
  21.             //same code stuffs here
  22.            
  23.             return Task.FromResult(GetViewModel());
  24.         }
  25.  
  26.         public abstract TResponse GetViewModel();
  27.     }
  28.     public class DummyQueryHandler_1 : AbstractDummyQueryHandler<DummyRequest_1, bool>
  29.     {
  30.         public override bool GetViewModel()
  31.         {
  32.             throw new NotImplementedException();
  33.         }
  34.     }
  35.  
  36.     public class DummyQueryHandler_2 : AbstractDummyQueryHandler<DummyRequest_2, string>
  37.     {
  38.         public override string GetViewModel()
  39.         {
  40.             throw new NotImplementedException();
  41.         }
  42.     }
  43. }
  44.  
RAW Paste Data