Пример #1
0
        public static async Task Main(string[] args)
        {
            // Plumbing --------------------------------------------
            var serviceProvider = Bootstrapper.GetServiceProvider();

            await serviceProvider.GetService <IEventStoreConnectionProvider>().Connect();

            var commandMediator = serviceProvider.GetService <CommandMediator>();
            var queryMediator   = serviceProvider.GetService <QueryMediator>();
            // -----------------------------------------------------


            // Register a new application
            var applicationId      = LoanApplicationId.NewId();
            var organisationNumber = new OrganisationNumber("5561682518", Country.Sweden);

            var registerApplicationCommand = new RegisterLoanApplication(applicationId)
            {
                OrganisationNumber = organisationNumber,
                RequestedAmount    = Money.Create(100000, Currency.SEK),
                VisitingAddress    = new Address("Demogatan 1", string.Empty, "41420", "Göteborg", "Sverige", string.Empty)
            };

            await commandMediator.MediateCommand(registerApplicationCommand);

            // Get data (Direct ES query)
            var loanApplicationView = await queryMediator.MediateQuery(new GetLoanApplicationById(applicationId));

            Log.Information("loanApplicationView: {View}", JsonConvert.SerializeObject(loanApplicationView, Formatting.Indented, SerializerSettings));


            // Approve application - Process + Builder
            await commandMediator.MediateCommand(new ApproveLoanApplication(applicationId));


            // Get data again (Direct ES query)
            var loanApplicationView2 = await queryMediator.MediateQuery(new GetLoanApplicationById(applicationId));

            Log.Information("loanApplicationView: {View}", JsonConvert.SerializeObject(loanApplicationView2, Formatting.Indented, SerializerSettings));


            // Credits for org number (ReadModel)
            var credits = await queryMediator.MediateQuery(new GetCreditsByOrganisationNumber(organisationNumber));


            // Get credit data (Direct ES query)
            var creditView = await queryMediator.MediateQuery(new GetCreditById(credits.FirstOrDefault()));

            Log.Information("creditView: {View}", JsonConvert.SerializeObject(creditView, Formatting.Indented, SerializerSettings));


            // Register disbursement payout
            await commandMediator.MediateCommand(new RegisterDisbursementPayout(credits.FirstOrDefault(), Money.Create(100000, Currency.SEK)));


            // Get credit again data (Direct ES query)
            var creditView2 = await queryMediator.MediateQuery(new GetCreditById(credits.FirstOrDefault()));

            Log.Information("creditView: {View}", JsonConvert.SerializeObject(creditView2, Formatting.Indented, SerializerSettings));
        }
Пример #2
0
        public async Task <LoanApplication> GetById(LoanApplicationId loanApplicationId)
        {
            var domainEvents = await _eventStore.GetEventsByStreamId(new LoanApplicationEventStreamId(loanApplicationId));

            if (domainEvents.Count == 0)
            {
                return(null);
            }

            return(new LoanApplication(loanApplicationId, domainEvents.Cast <LoanApplicationDomainEvent>()));
        }
        public async Task <LoanApplicationViewModel> GetById(LoanApplicationId applicationId)
        {
            var domainEvents = await _eventStore.GetEventsByStreamId(new LoanApplicationEventStreamId(applicationId));

            if (domainEvents.Count == 0)
            {
                return(null);
            }

            var model = new LoanApplicationViewModel(applicationId);

            foreach (var domainEvent in domainEvents.Cast <LoanApplicationDomainEvent>())
            {
                _projection.Apply(model, domainEvent);
            }

            return(model);
        }
Пример #4
0
 public DenyLoanApplication(LoanApplicationId applicationId)
 {
     Id = applicationId;
 }
Пример #5
0
 public GetLoanApplicationById(LoanApplicationId applicationId)
 {
     ApplicationId = applicationId;
 }
 public LoanApplicationEventStreamId(LoanApplicationId id)
 {
     _id = id.ToString();
 }
 public ApproveLoanApplication(LoanApplicationId applicationId)
 {
     Id = applicationId;
 }
Пример #8
0
 public LoanApplicationViewModel(LoanApplicationId id)
 {
     Id = id;
 }
 public CreditRegisteredFromLoanApplication(LoanApplicationId loanApplicationId)
 {
     LoanApplicationId = loanApplicationId;
 }
Пример #10
0
 public RegisterLoanApplication(LoanApplicationId applicationId)
 {
     Id = applicationId;
 }