Exemplo n.º 1
0
        public ApiService(SolutionStack stack, string serviceName, Persistence included, bool registerSwagger = true)
        {
            _name = $"{stack.Prefix}{serviceName}";

            if (included.HasFlag(Persistence.AzureSql))
            {
                var db = new Database($"{serviceName}", new DatabaseArgs
                {
                    ResourceGroupName             = stack.RGName,
                    ServerName                    = stack.SqlServerName,
                    RequestedServiceObjectiveName = "S0"
                });

                _database          = db.Name;
                DbConnectionString = stack.ConnectionStringFor(_database);
            }

            var a = new AppService(_name, new AppServiceArgs
            {
                ResourceGroupName = stack.RGName,
                AppServicePlanId  = stack.AppServicePlanId,
                Tags        = stack.StandardTags(),
                AppSettings =
                {
                    { "APPLICATIONINSIGHTS_CONNECTION_STRING", Output.Format($"InstrumentationKey={stack.AppInsightsKey}") }
                },
                ConnectionStrings = GenerateConnStrings(included)
            });

            var r = AppRegistration(a);

            ApiClientId = r.ApplicationId;
            ApiUri      = r.IdentifierUris.First();

            if (registerSwagger)
            {
                var s = SwaggerRegistration(a, r);
                _apiSwaggerClientId = s.ApplicationId;
            }
        }