Exemple #1
0
        /// <summary><para>Used when a user manually creates an account themselves.</para>
        /// <para>Note how this design with a named static creation method: </para>
        /// <para> * makes it clearear what the caller intends.</para>
        /// <para> * makes it impossible to use the class incorrectly, such as forgetting to check for duplicates or save the new instance in the repository.</para>
        /// <para> * reduces code duplication since multiple callers are not burdened with saving the instance, checking for duplicates etc.</para>
        /// </summary>
        public static Account Register(
            Email email,
            Password password,
            Guid accountId,
            IAccountRepository repository,
            IDuplicateAccountChecker duplicateAccountChecker)
        {
            //Ensure that it is impossible to call with invalid arguments.
            //Since all domain types should ensure that it is impossible to create a non-default value that is invalid we only have to disallow default values.
            Contract.Argument(() => email, () => password, () => accountId, () => repository, () => duplicateAccountChecker).NotNullOrDefault();

            //The email is the unique identifier for logging into the account so obviously duplicates are forbidden.
            duplicateAccountChecker.AssertAccountDoesNotExist(email);

            var created = new Account();

            created.RaiseEvent(new UserRegisteredAccountEvent(accountId: accountId, email: email, password: password));
            repository.Add(created);

            return(Contract.Return(created, inspect => inspect.NotNull())); //Promise and ensure that you will never return null.
        }
 public void SetupWiringAndCreateRepositoryAndScope()
 {
     _repository = Container.Resolve<IAccountRepository>();
     _duplicateAccountChecker = Container.Resolve<IDuplicateAccountChecker>();
     _registerAccountScenario = new RegisterAccountScenario(Container);
 }
 public void SetupWiringAndCreateRepositoryAndScope()
 {
     _repository = Container.Resolve <IAccountRepository>();
     _duplicateAccountChecker = Container.Resolve <IDuplicateAccountChecker>();
     _registerAccountScenario = new RegisterAccountScenario(Container);
 }