public static async Task CreateUserNoHash() { var container = ContainerGenerator.StartNew() .WithDbContext() .WithUnitOfWork() .Generate(); container.Register <IUserRepository, UserRepository>(); container.Register <IPasswordHashService, DoNothingPasswordHashService>(); container.Register <UserService>(); using (var scope = AsyncScopedLifestyle.BeginScope(container)) { var userService = container.GetInstance <UserService>(); await userService.Create(new Models.UserCreateModel { CleartextPassword = "******", Email = $"f@ke-{Guid.NewGuid().ToString("n").Substring(0, 6)}.com", FirstName = "Mike", LastName = "Devlin" }); await scope.DisposeAsync(); } }
public static async Task CreateUserWithHash() { var container = ContainerGenerator.StartNew() .WithDbContext() .WithUnitOfWork() .Generate(); container.Register <IUserRepository, UserRepository>(); container.Register <IPasswordHashService, BCryptPasswordHashService>(); container.Register <UserService>(); container.Register <AuthenticationService>(); var email = $"f@ke-{Guid.NewGuid().ToString("n").Substring(0, 6)}.com"; using (var scope = AsyncScopedLifestyle.BeginScope(container)) { var userService = container.GetInstance <UserService>(); await userService.Create(new Models.UserCreateModel { CleartextPassword = "******", Email = email, FirstName = "Mike", LastName = "Devlin" }); await scope.DisposeAsync(); } using (var scope = AsyncScopedLifestyle.BeginScope(container)) { var authService = container.GetInstance <AuthenticationService>(); var happyResult = await authService.Authenticate(email, "password"); System.Console.WriteLine($"Happy result: {happyResult}"); var sadResult = await authService.Authenticate(email, ""); System.Console.WriteLine($"Sad result: {sadResult}"); } }