public static CqrsContext AddDistributedCache(this CqrsContext context) { context.Services.Add(new ServiceDescriptor( typeof(IPipelineBehavior <,>), typeof(CacheBehaviour <,>), context.ServiceLifetime)); return(context); }
public static CqrsContext AddValidation(this CqrsContext context) { context.Services.Add(new ServiceDescriptor( typeof(IPipelineBehavior <,>), typeof(ValidationBehaviour <,>), context.ServiceLifetime)); return(context); }
public static CqrsContext AddErrorHandler(this CqrsContext context) { context.Services.Add(new ServiceDescriptor( typeof(IPipelineBehavior <,>), typeof(ErrorHandlerBehaviour <,>), context.ServiceLifetime)); return(context); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, CqrsContext cqrsContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseMvc(); cqrsContext.Database.EnsureCreated(); }
public async Task AfterExecute(CreateAdmissionCommand cmd, CqrsContext ctx, CancellationToken cancellationToken = new CancellationToken()) { var visitor = await _visitorsRepository.GetById(new ObjectId(cmd.VisitorId)); var msg = $"Уважаемый(-ая) {visitor.FirstName}, будем рады видеть Вас в нашем офисе"; using (var client = new HttpClient()) { var r = await client.GetAsync($"https://smsc.ru/sys/send.php?login=movchinnikov&psw=qwerty&phones={visitor.PhoneNumber}&mes={msg}"); } }
public async Task <TResult> ExecuteQuery <TQuery, TResult>(TQuery query, CqrsContext ctx, CancellationToken cancellationToken = new CancellationToken()) where TQuery : IQuery <TResult> { if (query == null) { throw new ArgumentNullException(nameof(query), "Запрос не передан"); } var handler = _container.Resolve <IQueryHandler <TQuery, TResult> >(); if (handler == null) { throw new NotImplementedException($"Не определен обработчик для запроса {query.GetType()}"); } return(await handler.Execute(query, ctx, cancellationToken)); }
public async Task ExecuteCommand <TCommand>(TCommand cmd, CqrsContext ctx, CancellationToken cancellationToken = new CancellationToken()) where TCommand : ICommand { if (cmd == null) { throw new ArgumentNullException(nameof(cmd), "Команда не передана"); } var handler = _container.Resolve <ICommandHandler <TCommand> >(); if (handler == null) { throw new NotImplementedException($"Не определен обработчик для команды {cmd.GetType()}"); } await handler.Execute(cmd, ctx, cancellationToken); var afterHandlers = _container.ResolveAll <IAfterCommandHandler <TCommand> >(); foreach (var afterCommandHandler in afterHandlers) { await afterCommandHandler.AfterExecute(cmd, ctx, cancellationToken); } }
public CandidateRepository(CqrsContext context) : base(context) { }
public QueryRepository(CqrsContext context) { _context = context; }
public async Task Execute(UpdateAdmissionCommand cmd, CqrsContext ctx, CancellationToken cancellationToken = new CancellationToken()) { var entity = new Admission(cmd); await _admissionRepository.Update(entity); }
public UserRepository(CqrsContext context) { _context = context; }
public async Task <IEnumerable <AdmissionResponse> > Execute(GetAdmissionsQuery cmd, CqrsContext ctx, CancellationToken cancellationToken = new CancellationToken()) { var entities = await _admissionRepository.GetAllByVisitor(new ObjectId(cmd.VisitorId)); var dtos = entities.Select(x => new AdmissionResponse(x)); return(dtos); }
public async Task Execute(DeleteAdmissionCommand cmd, CqrsContext ctx, CancellationToken cancellationToken = new CancellationToken()) { await _admissionRepository.Delete(new ObjectId(cmd.VisitorId), new ObjectId(cmd.AdmissionId)); }
public async Task Execute(CreateAdmissionCommand cmd, CqrsContext ctx, CancellationToken cancellationToken = new CancellationToken()) { var admission = new Admission(cmd); await _admissionRepository.Create(admission); }
public async Task <AdmissionResponse> Execute(GetAdmissionQuery cmd, CqrsContext ctx, CancellationToken cancellationToken = new CancellationToken()) { var entity = await _admissionRepository.Get(new ObjectId(cmd.VisitorId), new ObjectId(cmd.AdmissionId)); return(new AdmissionResponse(entity)); }
public BaseRepository(CqrsContext context) { _dbContext = context; _dbSet = _dbContext.Set <TEntity>(); }
public async Task <IEnumerable <VisitorResponse> > Execute(GetVisitorsQuery cmd, CqrsContext ctx, CancellationToken cancellationToken = new CancellationToken()) { var entities = await _visitorsRepository.GetAll(); var dtos = entities.Select(x => new VisitorResponse(x)); return(dtos); }
public CommandRepository(CqrsContext context) { _context = context; }
public async Task Execute(DeleteVisitorCommand cmd, CqrsContext ctx, CancellationToken cancellationToken = new CancellationToken()) { await _visitorsRepository.Delete(new ObjectId(cmd.Id)); }
public async Task Execute(UpdateVisitorCommand cmd, CqrsContext ctx, CancellationToken cancellationToken = new CancellationToken()) { var visitor = new Visitor(cmd); await _visitorsRepository.Update(visitor); }
public async Task AfterExecute(CreateVisitorCommand cmd, CqrsContext ctx, CancellationToken cancellationToken = new CancellationToken()) { var command = new CreateAdmissionCommand(cmd); await _cqrsDispatcher.ExecuteCommand(command, ctx, cancellationToken); }
public async Task <VisitorResponse> Execute(GetVisitorQuery cmd, CqrsContext ctx, CancellationToken cancellationToken = new CancellationToken()) { var entity = await _visitorsRepository.GetById(new ObjectId(cmd.Id)); return(new VisitorResponse(entity)); }