// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddAutofac(); // Add framework services. services.AddMvc().AddControllersAsServices(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "Stove Web Api", Version = "v1" }); }); IocBuilder builder = IocBuilder.New; RootResolver = builder.UseStove <StoveWebApiCoreBootstrapper>() .UseStoveEntityFrameworkCore(configuration => configuration) .AddStoveDbContext <AnimalDbContext>(contextConfiguration => { if (contextConfiguration.ExistingConnection != null) { contextConfiguration.DbContextOptions.UseSqlServer(contextConfiguration.ExistingConnection); } else { contextConfiguration.DbContextOptions.UseSqlServer(Configuration.GetConnectionString("Default")); } }) .AddStoveDbContext <PersonDbContext>(contextConfiguration => { if (contextConfiguration.ExistingConnection != null) { contextConfiguration.DbContextOptions.UseSqlServer(contextConfiguration.ExistingConnection); } else { contextConfiguration.DbContextOptions.UseSqlServer(Configuration.GetConnectionString("Default")); } }) .UseStoveDapper() .UseStoveTypedConnectionStringResolver() .UseStoveEventBus() .UseStoveBackgroundJobs() .UseStoveMapster() .UseStoveHangfire(configuration => { configuration.GlobalConfiguration .UseSqlServerStorage(Configuration.GetConnectionString("Default")) .UseNLogLogProvider(); return(configuration); }) .UseStoveNLog() .UseStoveRabbitMQ(configuration => { configuration.HostAddress = "rabbitmq://localhost/"; configuration.Username = "******"; configuration.Password = "******"; configuration.QueueName = "NetCore2"; return(configuration); }) .UseStoveRedisCaching(configuration => { configuration.ConfigurationOptions .AddEndpoint("127.0.0.1") .SetDefaultDatabase(0) .SetConnectionTimeOut(TimeSpan.FromMinutes(5)); return(configuration); }) .RegisterServices(r => { r.RegisterAssemblyByConvention(typeof(Startup).GetAssembly()); r.BeforeRegistrationCompleted += (sender, args) => { args.ContainerBuilder.Populate(services); }; }) .CreateResolver(); RootResolver.Resolve <ILogger>().Error("anan"); return(new AutofacServiceProvider(RootResolver.Container)); }