如何使用构造函数依赖项注入对asp.net核心应用程序进行单元测试
我有一个使用应用程序的startup.cs类中定义的依赖项注入的asp.net核心应用程序: public void ConfigureServices(IServiceCollection services) { services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration["Data:FotballConnection:DefaultConnection"])); // Repositories services.AddScoped<IUserRepository, UserRepository>(); services.AddScoped<IUserRoleRepository, UserRoleRepository>(); services.AddScoped<IRoleRepository, RoleRepository>(); services.AddScoped<ILoggingRepository, LoggingRepository>(); // Services services.AddScoped<IMembershipService, MembershipService>(); services.AddScoped<IEncryptionService, EncryptionService>(); // new repos services.AddScoped<IMatchService, MatchService>(); services.AddScoped<IMatchRepository, MatchRepository>(); services.AddScoped<IMatchBetRepository, MatchBetRepository>(); services.AddScoped<ITeamRepository, TeamRepository>(); services.AddScoped<IFootballAPI, FootballAPIService>(); 这允许这样的事情: [Route("api/[controller]")] public class MatchController : AuthorizedController { private readonly IMatchService _matchService; …