Пример #1
0
        public async Task <Guid> RegisterUser(Commands.RegisterUser command)
        {
            // Check if user already exists
            var existingUser = await _queryModelRepository.QueryItem <UserQueryModel>(x => x.DisplayName == $"{command.FirstName} {command.LastName}");

            if (existingUser != null)
            {
                return(existingUser.id);
            }

            // Create aggregate
            var newUserId = Guid.NewGuid();
            var user      = new User(newUserId);

            // Create domain command
            var domainCommand = new Core.Commands.RegisterUser(
                command.FirstName,
                command.LastName);

            // Fire command and wait for status response
            user.Tell(domainCommand);

            // Save User aggregate
            // Note: This saves the events published internally by the User Aggregate)
            await _aggregateStore.Save(user);

            return(newUserId);
        }
Пример #2
0
        public async Task Run()
        {
            // Create sample application command
            var registerUser = new Application.Commands.RegisterUser(firstName: "Donald", lastName: "Duck");

            // Invoke sample application service
            var userId = await UserApplicationService.RegisterUser(registerUser);

            // Wait one second for the Read model to be updated.
            // This is much, much more than usually needed.
            Thread.Sleep(1000);

            // Get the query model
            UserQueryModel queryModel = await UserProjection.QueryById(userId);

            Console.WriteLine($"Query models Display Name: {queryModel.DisplayName}");

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }