示例#1
0
        public UserUseCases()
        {
            _token          = Guid.NewGuid().ToString("N");
            _passwordHasher = s => Convert.ToBase64String(MD5.Create().ComputeHash(Encoding.ASCII.GetBytes(s)));
            _keyStore       = new ReallyInsecureAndVeryTemporaryKeyStore();
            _keyStore.CreateKeyIfNotExists("test");
            SerializationRegistry serializationRegistry = new SerializationRegistry();

            UserBoundedContext.RegisterSerializers(serializationRegistry, _keyStore);
            IKnownSerializers serialization = serializationRegistry.Build();

            _eventStore = new TestEventStore(serialization);
            CommandRegistry commandRegistry = new CommandRegistry();

            _lockoutPolicy = () => Clock.Now + TimeSpan.FromMinutes(5);
            UserBoundedContext.RegisterCommands(
                commandRegistry,
                new UserRepository(_eventStore, serialization),
                tokenSource: () => _token,
                passwordHasher: _passwordHasher,
                maxLoginAttempts: 3,
                lockoutPolicy: _lockoutPolicy);
            _handler         = commandRegistry.Build();
            _now             = DateTimeOffset.UtcNow;
            Clock.UtcNowFunc = () => _now;
        }