private void SetProjectionListener(LoansRepository repository, IServiceCollection services) { var config = new RabbitMqConfig(); configuration.GetSection("RabbitMq").Bind(config); var logger = services.BuildServiceProvider().GetService <ILogger <RabbitMqPublisher> >(); var rabbitMq = new RabbitMqChannelFactory().CreateReadChannel <Models.Loan, string>(config, "LoansRead", logger); rabbitMq.Received += (sender, projection) => { if (projection.Upsert != null && projection.Upsert.Length > 0) { repository.Upsert(projection.Upsert); } if (projection.Upsert != null && projection.Upsert.Length == 0) { repository.Clear(); } if (projection.Remove != null) { repository.Remove(projection.Remove); } }; }