public ApplicationDbContext CreateDbContext(string[] args) { var appSettings = UtilitarioDeArquivos.CarregueJsonArquivo("appsettings.json"); var conexaoDoBanco = appSettings.ConnectionStrings.DefaultConnection; var conexaoDoBancoString = ((JValue)conexaoDoBanco).Value as string; var builder = new DbContextOptionsBuilder <ApplicationDbContext>(); builder.UseSqlServer(conexaoDoBancoString); return(new ApplicationDbContext(builder.Options)); }
public static IServiceProvider ObtenhaProviderMock() { var configuracao = UtilitarioDeArquivos.CarregueJsonArquivo("appsettings.json"); var conexaoDoBanco = configuracao.BDTeste.SQliteBDConnectionString; var conexaoDoBancoString = ((JValue)conexaoDoBanco).Value as string; var services = new ServiceCollection(); services.AddTransient(typeof(IRecadoServico <Recado>), typeof(RecadoServico)); services.AddTransient(typeof(IAgrupamentoServico <Agrupamento>), typeof(AgrupamentoServico)); services.AddDbContext <ApplicationDbContext>(options => options.UseSqlite(conexaoDoBancoString, x => x.SuppressForeignKeyEnforcement()) .EnableSensitiveDataLogging()); var serviceProvider = services.BuildServiceProvider(); return(serviceProvider); }