Пример #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            if (Environment.IsDevelopment())
            {
                services.AddDbContext <DataContext>(options =>
                                                    options.UseLazyLoadingProxies()
                                                    .UseNpgsql(Configuration.GetConnectionString("DefaultConnection")));
            }
            else
            {
                services.AddDbContext <DataContext>(options =>
                                                    options.UseLazyLoadingProxies()
                                                    .UseSqlServer(Configuration.GetConnectionString("SqlServerConnection")));
            }

            services.AddControllersWithViews().AddMvcOptions(options =>
            {
                options.ModelBinderProviders.Insert(0, new CustomModelBinderProvider());
            });

            // In production, the Angular files will be served from this directory
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/dist";
            });

            services.AddSingleton <IFileProvider>(FileProvider.GetInstance(Environment, Configuration));

            services.AddSignalR().AddMessagePackProtocol();
        }