/// <inheritdoc /> public override void OnInitialize(TestRunExecutionContext context) { var builder = new ContainerBuilder(); DiConfig.Setup(builder, testingMode: true); container = builder.Build(); ServiceProviderFactory = new AutofacServiceProviderFactory(container); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { // Add framework services. services.AddMvc(); var builder = DiConfig.Setup(); builder.Register(c => LoggerConfig.Setup(c.Resolve <ConfigTokenHandler <SeqUriToken> >(), c.Resolve <ConfigTokenHandler <LogFilePath> >(), c.Resolve <ConfigTokenHandler <LogToFile> >())).As <Serilog.ILogger>().SingleInstance(); builder.Register(c => Configuration).As <IConfigurationRoot>().SingleInstance(); builder.Populate(services); ApplicationContainer = builder.Build(); using (var lifetimeScope = ApplicationContainer.BeginLifetimeScope()) { var logger = lifetimeScope.Resolve <Serilog.ILogger>(); logger.Information("Application Starting.."); } return(new AutofacServiceProvider(ApplicationContainer)); }