Exemple #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            //service DI
            //services.AddDbContext<DatabaseContext>(options =>
            //options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection_sql_server")));

            services.AddDbContext <DatabaseContext>(options =>
                                                    options.UseSqlite(Configuration.GetConnectionString("DefaultConnection_sqlite")));

            // Create Database when Database not found (code first)
            var serviceProvider = services.BuildServiceProvider();

            DatabaseInit.INIT(serviceProvider);

            //Web Service
            services.AddTransient <ProductService>();

            //Acess Hosting
            services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            //Service Upload Image
            services.AddSingleton <UtilService>();
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            services.AddDbContext <DatabaseContext>(x => x.UseSqlServer(Configuration["ConnectionString:sqlcon"]));

            var serviceProvider = services.BuildServiceProvider();

            DatabaseInit.INIT(serviceProvider);

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

                // options.AddPolicy("AllowSpecific", builder =>
                // {
                //     builder.WithOrigins("http://localhost:xxx","http://localhost:yyy")
                //            .AllowAnyHeader().AllowAnyMethod();
                // });
            });
            services.AddControllersWithViews()
            .AddNewtonsoftJson(options =>
                               options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
                               );
        }
Exemple #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            services.AddDbContext <DatabaseContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection_sql_server")));
            var serviceProvider = services.BuildServiceProvider();

            DatabaseInit.INIT(serviceProvider);
        }
        public static void ConfigDatabase(this IServiceCollection services, IConfiguration configuration)
        {
            // Connection Database SqlServar
            services.AddDbContext <Database.DatabaseContext>(option =>
                                                             option.UseSqlServer(configuration.GetConnectionString("DefaultConnection_sql_server")));

            // Check Database Ensure Created
            var serviceProvider = services.BuildServiceProvider();

            DatabaseInit.INIT(serviceProvider);
        }