Example #1
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddMvc();
     services.Configure <ConnectionStrings>(Configuration.GetSection("ConnectionStrings"));
     DIConfig.RegisterTypes(services);
     ServiceDIConfig.RegisterTypes(services);
     services.AddSwaggerGen(c =>
     {
         c.SwaggerDoc("v1", new Info
         {
             Version = "v1",
             Title   = "API",
         });
     });
     services.AddCors(options =>
     {
         options.AddPolicy("AllowAll",
                           builder =>
         {
             builder
             .AllowAnyOrigin()
             .AllowAnyMethod()
             .AllowAnyHeader()
             .AllowCredentials();
         });
     });
 }
Example #2
0
        public static ServiceProvider GetServiceProvider()
        {
            IServiceCollection   services = new ServiceCollection();
            ConfigurationBuilder builder  = new ConfigurationBuilder();

            builder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

            IConfiguration configuration = builder.Build();

            services.AddSingleton <IConfiguration>(configuration);
            services.AddOptions();
            services.Configure <ConnectionStrings>(configuration.GetSection("ConnectionStrings"));
            var k = configuration.GetConnectionString("DBConnection");

            ServiceDIConfig.RegisterTypes(services);

            DIConfig.RegisterTypes(services);

            return(services.BuildServiceProvider());
        }