public void ConfigureServices()

in MIG - Migrating Applications to the Cloud/MIG50/src/inventory-service/InventoryService.Api/Startup.cs [32:76]


        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            services.AddSwagger();
            services.AddDbContext<InventoryContext>(options =>
            {
                var connectionString = Configuration.GetConnectionString("InventoryContext");
                isPostgres = connectionString.Contains("postgres");
                if (isPostgres)
                {
                    options.UseNpgsql(connectionString);
                }
                else
                {
                    options.UseSqlServer(connectionString);
                }
            });
            services.AddCors();
            var signalR = services.AddSignalR()
                .AddJsonProtocol(builder =>
                    builder.PayloadSerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver());
            if (useSignalRService)
            {
                signalR.AddAzureSignalR(signalRServiceConnectionString);
            }
            services.AddScoped<InventoryManager>();
            services.AddScoped<IInventoryData, SqlInventoryData>();
            services.AddScoped<IInventoryNotificationService, SignalRInventoryNotificationService>();
            services.AddScoped<SqlConnection>(_ =>
            {
                if (isPostgres)
                {
                    return null;
                }

                var connectionString = Configuration.GetConnectionString("InventoryContextReadOnly");
                if (string.IsNullOrEmpty(connectionString))
                {
                    connectionString = Configuration.GetConnectionString("InventoryContext");
                }

                return new SqlConnection(connectionString);
            });
            services.AddScoped<BadSqlInventoryData>();
        }