Ejemplo n.º 1
0
        // 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.AddMvcCore()
            .AddJsonOptions(options =>
            {
                options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            })
            .AddJsonFormatters()
            .AddFormatterMappings();

            var connection = this.Configuration.GetConnectionString();

            services.AddDbContext <QuestionsContext>(options =>
                                                     options.UseSqlServer(connection)
                                                     );

            services.AddCors();

            // Autofac
            var containerBuilder = new ContainerBuilder();

            containerBuilder.AddApi()
            .AddData();

            containerBuilder.Populate(services);
            var applicationContainer = containerBuilder.Build();

            return(new AutofacServiceProvider(applicationContainer));
        }