using System.Collections.Generic; public interface IUsersService { void AddUser(User newUser); } public class User { public string Name { get; set; } public string Email { get; set; } } public class UsersService : IUsersService { private Listusers = new List (); public void AddUser(User newUser) { users.Add(newUser); Console.WriteLine("User added successfully."); } }
using Microsoft.AspNetCore.Identity; public interface IUsersService { TaskIn this example, the AddUser method takes a User object and a password as parameters, and uses the UserManager from the Microsoft.AspNetCore.Identity package to create a new user with the specified credentials. The method returns an IdentityResult object that indicates whether the user creation was successful.AddUser(User newUser, string password); } public class UsersService : IUsersService { private readonly UserManager userManager; public UsersService(UserManager userManager) { this.userManager = userManager; } public async Task AddUser(User newUser, string password) { var result = await userManager.CreateAsync(newUser, password); if (result.Succeeded) { Console.WriteLine("User added successfully."); } return result; } }