protected override IServiceProvider CreateContainer()
        {
            IKernel kernel = new StandardKernel();

            kernel.Populate(TestServices.DefaultServices());

            return kernel.Get<IServiceProvider>();
        }
Example #2
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc();

            // Create a new Ninject kernel for your bindings
            var kernel = new StandardKernel();

            // Set up your bindings for DI
            kernel.Load<HelloMvcModule>();

            // Add all the ASP.NET services to your Ninject kernel
            kernel.Populate(services);

            // Use Ninject to return an instance
            return kernel.Get<IServiceProvider>();
        }
Example #3
0
        //// This method gets called by a runtime.
        //// Use this method to add services to the container
        //public void ConfigureServices(IServiceCollection services)
        //{
        //    services.AddMvc();
        //    // Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers.
        //    // You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json.
        //    // services.AddWebApiConventions();
        //}
        // You probably need to change this return type - defaults to void
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            //IServiceProvider
            // Add your various services such as MVC as normal
            services.AddMvc();

            services.AddCors();
            services.ConfigureCors(options =>
            {
                options.AddPolicy("AllowAll",
                    builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());
            });

            //http://docs.asp.net/en/latest/security/cors.html
            //services.ConfigureCors(options =>
            //{
            //    options.AddPolicy("AllowSpecificOrigin",
            //        builder => builder.WithOrigins("http://example.com"));
            //});

            // Use Ninject to return an instance
            // Create a new Ninject kernel for your bindings
            var kernel = new StandardKernel(new DataModule(Configuration["Data:DataConnection:ConnectionString"]),
                new AutomapperNinjectModule(), new ServicesModule());

            kernel.Populate(services);

            return kernel.Get<IServiceProvider>();
        }