[Fixes #70]
This commit is contained in:
Chris Cheetham 2021-02-05 14:25:02 -05:00
Родитель 5361822e40
Коммит 366f27a398
15 изменённых файлов: 1089 добавлений и 2 удалений

Просмотреть файл

@ -1,7 +1,7 @@
description: Steeltoe 2.5.x, netcoreapp3.1, webapi, C#
constraints:
steeltoeVersionRange: "[2.5.0,3.0.0)"
dotNetFrameworkRange: "netcoreapp3.1"
dotNetFrameworkRange: "[netcoreapp3.1,net5.0)"
dotNetTemplate: webapi
language: csharp
manifest:

Просмотреть файл

@ -0,0 +1,55 @@
description: Steeltoe 3.0.x, netcoreapp3.1, webapi, C#
constraints:
steeltoeVersionRange: 3.0.0
dotNetFrameworkRange: net5.0
dotNetTemplate: webapi
language: csharp
manifest:
- path: app.config
- path: appsettings.json
- path: Dockerfile
dependencies: docker
- path: MyCircuitBreakerCommand.cs
dependencies: circuit-breaker
- path: Program.cs
- path: ReplaceMe.csproj
rename: "{{Name}}.csproj"
- path: Startup.cs
- path: Controllers/
- path: Controllers/ValuesController.cs
- path: Models/
- path: Models/ErrorViewModel.cs
dependencies: any-efcore
- path: Models/TestContext.cs
dependencies: any-efcore
- path: Properties/
- path: Properties/launchSettings.json
parameters:
- name: asp-dotnet-core-version
value: 5.0.*
- name: mongodb-version
value: 2.8.*
- name: mysql-version
value: 8.0.*
- name: npgsql-version
value: 4.0.*
- name: rabbitmq-version,
value: 5.1.*
- name: actuator-or-cloud-foundry
expression: actuator || cloud-foundry
- name: actuator-or-dynamic-logger
expression: actuator || dynamic-logger
- name: any-config-source
expression: config-server || placeholder || random-value
- name: any-connector
expression: data-mongodb || mysql || oauth || postgresql || amqp || data-redis || sqlserver
- name: any-sql
expression: mysql || postgresql || data-mongodb || sqlserver
- name: any-efcore
expression: mysql-efcore || postgresql-efcore
- name: mysql-or-mysql-efcore
expression: mysql || mysql-efcore
- name: more-than-one-values-controller-with-args
expression: count(sqlserver, mysql, postgresql, data-mongodb, amqp, data-redis, config-server, placeholder, random-value, circuit-breaker, cloud-foundry) > 1
- name: values-controller-with-args
expression: sqlserver || mysql || postgresql || data-mongodb || amqp || data-redis || config-server || placeholder || random-value || circuit-breaker || cloud-foundry

232
src/steeltoe-3.0.x--net5.0--webapi--csharp/.gitignore поставляемый Normal file
Просмотреть файл

@ -0,0 +1,232 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
bin/
Bin/
obj/
Obj/
# Visual Studio 2015 cache/options directory
.vs/
/wwwroot/dist/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Microsoft Azure ApplicationInsights config file
ApplicationInsights.config
# Windows Store app package directory
AppPackages/
BundleArtifacts/
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
orleans.codegen.cs
/node_modules
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
*.mdf
*.ldf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
# FAKE - F# Make
.fake/

Просмотреть файл

@ -0,0 +1,331 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
{{#Auth}}
using Microsoft.AspNetCore.Authorization;
{{/Auth}}
using Microsoft.AspNetCore.Mvc;
{{#sqlserver}}
using System.Data.SqlClient;
using System.Data;
{{/sqlserver}}
{{#mysql}}
using MySql.Data.MySqlClient;
using System.Data;
{{/mysql}}
{{#postgresql}}
using Npgsql;
using System.Data;
{{/postgresql}}
{{#data-mongodb}}
using MongoDB.Driver;
using System.Data;
{{/data-mongodb}}
{{#data-redis}}
using Microsoft.Extensions.Caching.Distributed;
{{/data-redis}}
{{#amqp}}
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
using System.Text;
using System.Threading;
{{/amqp}}
{{#any-config-source}}
using Microsoft.Extensions.Configuration;
{{/any-config-source}}
{{#cloud-foundry}}
using Steeltoe.Extensions.Configuration.CloudFoundry;
using Microsoft.Extensions.Options;
{{/cloud-foundry}}
namespace {{Namespace}}.Controllers
{
{{#Auth}}
[Authorize]
{{/Auth}}
[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
{{^more-than-one-values-controller-with-args }}
{{#sqlserver}}
private readonly SqlConnection _dbConnection;
public ValuesController([FromServices] SqlConnection dbConnection)
{
_dbConnection = dbConnection;
}
// GET api/values
[HttpGet]
public ActionResult<IEnumerable<string>> Get()
{
List<string> tables = new List<string>();
_dbConnection.Open();
DataTable dt = _dbConnection.GetSchema("Tables");
_dbConnection.Close();
foreach (DataRow row in dt.Rows)
{
string tablename = (string)row[2];
tables.Add(tablename);
}
return tables;
}
{{/sqlserver}}
{{#mysql}}
private readonly MySqlConnection _dbConnection;
public ValuesController([FromServices] MySqlConnection dbConnection)
{
_dbConnection = dbConnection;
}
// GET api/values
[HttpGet]
public ActionResult<IEnumerable<string>> Get()
{
List<string> tables = new List<string>();
_dbConnection.Open();
DataTable dt = _dbConnection.GetSchema("Tables");
_dbConnection.Close();
foreach (DataRow row in dt.Rows)
{
string tablename = (string)row[2];
tables.Add(tablename);
}
return tables;
}
{{/mysql}}
{{#postgresql}}
private readonly NpgsqlConnection _dbConnection;
public ValuesController([FromServices] NpgsqlConnection dbConnection)
{
_dbConnection = dbConnection;
}
// GET api/values
[HttpGet]
public ActionResult<IEnumerable<string>> Get()
{
List<string> tables = new List<string>();
_dbConnection.Open();
DataTable dt = _dbConnection.GetSchema("Databases");
_dbConnection.Close();
foreach (DataRow row in dt.Rows)
{
string tablename = (string)row[2];
tables.Add(tablename);
}
return tables;
}
{{/postgresql}}
{{#data-mongodb}}
private readonly IMongoClient _mongoClient;
private readonly MongoUrl _mongoUrl;
public ValuesController(IMongoClient mongoClient, MongoUrl mongoUrl)
{
_mongoClient = mongoClient;
_mongoUrl = mongoUrl;
}
// GET api/values
[HttpGet]
public ActionResult<IEnumerable<string>> Get()
{
return _mongoClient.ListDatabaseNames().ToList();
}
{{/data-mongodb}}
{{#data-redis}}
private readonly IDistributedCache _cache;
public ValuesController(IDistributedCache cache)
{
_cache = cache;
}
// GET api/values
[HttpGet]
public async Task<IEnumerable<string>> Get()
{
await _cache.SetStringAsync("MyValue1", "123");
await _cache.SetStringAsync("MyValue2", "456");
string myval1 = await _cache.GetStringAsync("MyValue1");
string myval2 = await _cache.GetStringAsync("MyValue2");
return new string[]{ myval1, myval2};
}
{{/data-redis}}
{{#amqp}}
private readonly ILogger _logger;
private readonly ConnectionFactory _factory;
private const string queueName = "my-queue";
public ValuesController(ILogger<ValuesController> logger, [FromServices] ConnectionFactory factory)
{
_logger = logger;
_factory = factory;
}
// GET api/values
[HttpGet]
public ActionResult<string> Get()
{
using (var connection = _factory.CreateConnection())
using (var channel = connection.CreateModel())
{
//the queue
channel.QueueDeclare(queue: queueName,
durable: false,
exclusive: false,
autoDelete: false,
arguments: null);
// consumer
var consumer = new EventingBasicConsumer(channel);
consumer.Received += (model, ea) =>
{
string msg = Encoding.UTF8.GetString(ea.Body);
_logger.LogInformation("Received message: " + msg);
};
channel.BasicConsume(queue: queueName,
autoAck: true,
consumer: consumer);
// publisher
int i = 0;
while (i<5) { //write a message every second, for 5 seconds
var body = Encoding.UTF8.GetBytes($"Message {++i}");
channel.BasicPublish(exchange: "",
routingKey: queueName,
basicProperties: null,
body: body);
Thread.Sleep(1000);
}
}
return "Wrote 5 message to the info log. Have a look!";
}
{{/amqp}}
{{#config-server}}
private readonly IConfiguration _config;
public ValuesController(IConfiguration config)
{
_config = config;
}
// GET api/values
[HttpGet]
public ActionResult<IEnumerable<string>> Get()
{
var val1 = _config["Value1"];
var val2 = _config["Value2"];
return new string[] { val1, val2 };
}
{{/config-server}}
{{#placeholder}}
private readonly IConfiguration _config;
public ValuesController(IConfiguration config)
{
_config = config;
}
// GET api/values
[HttpGet]
public ActionResult<IEnumerable<string>> Get()
{
var val1 = _config["ResolvedPlaceholderFromEnvVariables"];
var val2 = _config["UnresolvedPlaceholder"];
var val3 = _config["ResolvedPlaceholderFromJson"];
return new string[] { val1, val2, val3 };
}
{{/placeholder}}
{{#random-value}}
private readonly IConfiguration _config;
public ValuesController(IConfiguration config)
{
_config = config;
}
// GET api/values
[HttpGet]
public ActionResult<IEnumerable<string>> Get()
{
var val1 = _config["random:int"];
var val2 = _config["random:uuid"];
var val3 = _config["random:string"];
return new string[] { val1, val2, val3 };
}
{{/random-value}}
{{#circuit-breaker}}
// GET api/values
[HttpGet]
public async Task<IEnumerable<string>> Get()
{
MyCircuitBreakerCommand cb = new MyCircuitBreakerCommand("ThisIsMyBreaker");
cb.IsFallbackUserDefined = true;
string a = await cb.ExecuteAsync();
return new string[] { a };
}
{{/circuit-breaker}}
{{#cloud-foundry}}
private readonly ILogger _logger;
private CloudFoundryApplicationOptions _appOptions { get; set; }
private CloudFoundryServicesOptions _serviceOptions { get; set; }
public ValuesController(ILogger<ValuesController> logger, IOptions<CloudFoundryApplicationOptions> appOptions, IOptions<CloudFoundryServicesOptions> serviceOptions)
{
_logger = logger;
_appOptions = appOptions.Value;
_serviceOptions = serviceOptions.Value;
}
// GET api/values
[HttpGet]
public ActionResult<IEnumerable<string>> Get()
{
string appName = _appOptions.ApplicationName;
string appInstance = _appOptions.ApplicationId;
/*_serviceOptions.Services["user-provided"]
.First(q => q.Name.Equals("xxxxxxx"))
.Credentials["xxxxxxx"].Value*/
return new string[] { appInstance, appName };
}
{{/cloud-foundry}}
{{/more-than-one-values-controller-with-args}}
{{#more-than-one-values-controller-with-args}}
[HttpGet]
public ActionResult<string> Get()
{
return "value";
}
{{/more-than-one-values-controller-with-args}}
{{^values-controller-with-args}}
[HttpGet]
public ActionResult<string> Get()
{
return "value";
}
{{/values-controller-with-args}}
// GET api/values/5
[HttpGet("{id}")]
public ActionResult<string> Get(int id)
{
return "value";
}
// POST api/values
[HttpPost]
public void Post([FromBody] string value)
{
}
// PUT api/values/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}
// DELETE api/values/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}

Просмотреть файл

@ -0,0 +1,18 @@
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src
COPY ["{{Namespace}}.csproj", "."]
RUN dotnet restore "{{Namespace}}.csproj"
COPY . .
RUN dotnet build "{{Namespace}}.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "{{Namespace}}.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "{{Namespace}}.dll"]

Просмотреть файл

@ -0,0 +1,11 @@
using System;
namespace {{Namespace}}
{
public class ErrorViewModel
{
public string RequestId { get; set; }
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
}
}

Просмотреть файл

@ -0,0 +1,25 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace {{Namespace}}
{
public class TestContext : DbContext
{
public TestContext(DbContextOptions options) : base(options)
{
}
public DbSet<TestData> TestData { get; set; }
}
public class TestData
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int Id { get; set; }
public string Data { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Steeltoe.CircuitBreaker.Hystrix;
namespace {{Namespace}}
{
public class MyCircuitBreakerCommand : HystrixCommand<string>
{
private string _name;
public MyCircuitBreakerCommand(string name): base(HystrixCommandGroupKeyDefault.AsKey("MyCircuitBreakerGroup"))
{
_name = name;
IsFallbackUserDefined = true;
}
protected override async Task<string> RunAsync()
{
return await Task.FromResult("Hello " + _name);
}
protected override async Task<string> RunFallbackAsync()
{
return await Task.FromResult("Hello " + _name + " via fallback");
}
}
}

Просмотреть файл

@ -0,0 +1,64 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
{{#azure-spring-cloud}}
using Microsoft.Azure.SpringCloud.Client;
{{/azure-spring-cloud}}
{{#actuator-or-dynamic-logger}}
using Steeltoe.Extensions.Logging;
{{/actuator-or-dynamic-logger}}
{{#cloud-foundry}}
using Steeltoe.Common.Hosting;
{{^config-server}}
using Steeltoe.Extensions.Configuration.CloudFoundry;
{{/config-server}}
{{/cloud-foundry}}
{{#config-server}}
using Steeltoe.Extensions.Configuration.ConfigServer;
{{/config-server}}
{{#placeholder}}
using Steeltoe.Extensions.Configuration.Placeholder;
{{/placeholder}}
{{#random-value}}
using Steeltoe.Extensions.Configuration.RandomValue;
{{/ random-value}}
namespace {{Namespace}}
{
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args)
.Build()
.Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args)
{
var builder = WebHost.CreateDefaultBuilder(args)
{{#cloud-foundry}}
.UseCloudHosting() //Enable listening on a Env provided port
{{^config-server}}
.AddCloudFoundryConfiguration() //Add cloudfoundry environment variables as a configuration source
{{/config-server}}
{{/cloud-foundry}}
{{#config-server}}
.AddConfigServer()
{{/config-server}}
{{#placeholder}}
.AddPlaceholderResolver()
{{/placeholder}}
{{#random-value}}
.ConfigureAppConfiguration((b) => b.AddRandomValueSource())
{{/random-value}}
{{#azure-spring-cloud}}
.UseAzureSpringCloudService()
{{/azure-spring-cloud}}
{{#actuator-or-dynamic-logger}}
.ConfigureLogging((context, builder) => builder.AddDynamicConsole())
{{/actuator-or-dynamic-logger}}
.UseStartup<Startup>();
return builder;
}
}
}

Просмотреть файл

@ -0,0 +1,46 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
{{#WindowsAuth}}
"windowsAuthentication": true,
"anonymousAuthentication": false,
{{/WindowsAuth}}
{{^WindowsAuth}}
"windowsAuthentication": false,
"anonymousAuthentication": true,
{{/WindowsAuth}}
"iisExpress": {
"applicationUrl": "http://localhost:8080",
{{#RequiresHttps}}
"sslPort": 44300
{{/RequiresHttps}}
{{^RequiresHttps}}
"sslPort": 0
{{/RequiresHttps}}
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"{{Namespace}}": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/values",
{{#RequiresHttps}}
"applicationUrl": "https://localhost:5001;http://localhost:5000",
{{/RequiresHttps}}
{{^RequiresHttps}}
"applicationUrl": "http://localhost:5000",
{{/RequiresHttps}}
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

Просмотреть файл

@ -0,0 +1,103 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>{{DotNetFramework}}</TargetFramework>
{{#Auth}}
<UserSecretsId >{{UserSecretsId}}</UserSecretsId>
{{/Auth}}
{{#ExcludeLaunchSettings}}
<NoDefaultLaunchSettingsFile>True</NoDefaultLaunchSettingsFile>
{{/ExcludeLaunchSettings}}
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>
<ItemGroup >
{{#oauth}}
<PackageReference Include="Microsoft.AspNetCore.Authentication.AzureAD.UI" Version="{{asp-dotnet-core-version}}" />
{{/oauth}}
{{#IndividualB2CAuth}}
<PackageReference Include="Microsoft.AspNetCore.Authentication.AzureADB2C.UI" Version="{{asp-dotnet-core-version}}}" />
{{/IndividualB2CAuth}}
{{#RequiresHttps}}
<PackageReference Include="Microsoft.AspNetCore.HttpsPolicy" Version="{{asp-dotnet-core-version}}" />
{{/RequiresHttps}}
{{#any-efcore}}
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="{{asp-dotnet-core-version}}" />
{{/any-efcore}}
{{#data-mongodb}}
<PackageReference Include="MongoDB.Driver" Version="{{mongodb-version}}" />
{{/data-mongodb}}
{{#mysql}}
<PackageReference Include="MySql.Data" Version="{{mysql-version}}" />
{{/mysql}}
{{#postgresql}}
<PackageReference Include="Npgsql" Version="{{npgsql-version}}" />
{{/postgresql}}
{{#circuit-breaker}}
<PackageReference Include="Steeltoe.CircuitBreaker.HystrixCore" Version="{{SteeltoeVersion}}" />
{{/circuit-breaker}}
{{#cloud-foundry}}
<PackageReference Include="Steeltoe.Common.Hosting" Version="{{SteeltoeVersion}}" />
{{/cloud-foundry}}
{{#any-connector}}
<PackageReference Include="Steeltoe.Connector.ConnectorCore" Version="{{SteeltoeVersion}}"/>
<PackageReference Include="Steeltoe.Connector.CloudFoundry" Version="{{SteeltoeVersion}}"/>
{{/any-connector}}
{{#any-efcore}}
<PackageReference Include="Steeltoe.Connector.EFCore" Version="{{SteeltoeVersion}}" />
{{/any-efcore}}
{{#sqlserver}}
<PackageReference Include="Steeltoe.Connector.EFCore" Version="{{SteeltoeVersion}}" />
{{/sqlserver}}
{{#eureka-client}}
<PackageReference Include="Steeltoe.Discovery.ClientCore" Version="{{SteeltoeVersion}}"/>
{{/eureka-client}}
{{#cloud-foundry}}
<PackageReference Include="Steeltoe.Extensions.Configuration.CloudFoundryCore" Version="{{SteeltoeVersion}}" />
{{/cloud-foundry}}
{{#placeholder}}
<PackageReference Include="Steeltoe.Extensions.Configuration.PlaceholderCore" Version="{{SteeltoeVersion}}" />
{{/placeholder}}
{{#actuator-or-cloud-foundry}}
<PackageReference Include="Steeltoe.Extensions.Logging.DynamicLogger" Version="{{SteeltoeVersion}}" />
{{/actuator-or-cloud-foundry}}
{{#dynamic-logger}}
<PackageReference Include="Steeltoe.Extensions.Logging.DynamicLogger" Version="{{SteeltoeVersion}}" />
{{/dynamic-logger}}
{{#actuator}}
{{#cloud-foundry}}
<PackageReference Include="Steeltoe.Management.CloudFoundryCore" Version="{{SteeltoeVersion}}" />
{{/cloud-foundry}}
{{^cloud-foundry}}
<PackageReference Include="Steeltoe.Management.EndpointCore" Version="{{SteeltoeVersion}}" />
{{/cloud-foundry}}
{{/actuator}}
{{#config-server}}
<PackageReference Include="Steeltoe.Extensions.Configuration.ConfigServerCore" Version="{{SteeltoeVersion}}" />
{{/config-server}}
{{#random-value}}
<PackageReference Include="Steeltoe.Extensions.Configuration.RandomValueBase" Version="{{SteeltoeVersion}}" />
{{/random-value}}
{{#azure-spring-cloud}}
<PackageReference Include="Microsoft.Azure.SpringCloud.Client" Version="2.0.0-preview.1" />
{{/azure-spring-cloud}}
{{#data-redis}}
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="3.1.0" />
{{/data-redis}}
{{#postgresql-efcore}}
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.0" />
{{/postgresql-efcore}}
{{#amqp}}
<PackageReference Include="RabbitMQ.Client" Version="{{rabbitmq-version,}}" />
{{/amqp}}
</ItemGroup>
{{#circuit-breaker}}
<ItemGroup Condition="'$(BUILD)' == ''">
<PackageReference Include="Steeltoe.CircuitBreaker.Hystrix.MetricsStreamCore" Version="{{SteeltoeVersion}}" />
</ItemGroup>
<ItemGroup Condition="'$(BUILD)' == 'LOCAL'">
<PackageReference Include="Steeltoe.CircuitBreaker.Hystrix.MetricsEventsCore" Version="{{SteeltoeVersion}}" />
<PackageReference Include="System.Threading.ThreadPool" Version="4.3.0" />
</ItemGroup>
{{/circuit-breaker}}
</Project>

Просмотреть файл

@ -0,0 +1,156 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
{{#data-mongodb}}
using Steeltoe.Connector.MongoDb;
{{/data-mongodb}}
{{#mysql-or-mysql-efcore}}
using Steeltoe.Connector.MySql;
{{/mysql-or-mysql-efcore}}
{{#mysql-efcore}}
using Steeltoe.Connector.MySql.EFCore;
{{/mysql-efcore}}
{{#oauth}}
using Steeltoe.Connector.OAuth;
{{/oauth}}
{{#postgresql}}
using Steeltoe.Connector.PostgreSql;
{{/postgresql}}
{{#postgresql-efcore}}
using Steeltoe.Connector.PostgreSql.EFCore;
{{/postgresql-efcore}}
{{#amqp}}
using Steeltoe.Connector.RabbitMQ;
{{/amqp}}
{{#data-redis}}
using Steeltoe.Connector.Redis;
{{/data-redis}}
{{#sqlserver}}
using Steeltoe.Connector.SqlServer.EFCore;
{{/sqlserver}}
{{#eureka-client}}
using Steeltoe.Discovery.Client;
{{/eureka-client}}
{{#actuator}}
{{#cloud-foundry}}
using Steeltoe.Management.CloudFoundry;
{{/cloud-foundry}}
{{^cloud-foundry}}
using Steeltoe.Management.Endpoint;
{{/cloud-foundry}}
{{/actuator}}
{{#RequiresHttps}}
using Microsoft.AspNetCore.HttpsPolicy;
{{/RequiresHttps}}
{{#Auth}}
using Microsoft.AspNetCore.Authentication;
{{/Auth}}
{{#OrganizationalAuth}}
using Microsoft.AspNetCore.Authentication.AzureAD.UI;
{{/OrganizationalAuth}}
{{#IndividualB2CAuth}}
using Microsoft.AspNetCore.Authentication.AzureADB2C.UI;
{{/IndividualB2CAuth}}
{{#circuit-breaker}}
using Steeltoe.CircuitBreaker.Hystrix;
{{/circuit-breaker}}
namespace {{Namespace}}
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
{{#OrganizationalAuth}}
services.AddAuthentication(AzureADDefaults.BearerAuthenticationScheme)
.AddAzureADBearer(options => Configuration.Bind("AzureAd", options));
{{/OrganizationalAuth}}
{{#IndividualB2CAuth}}
services.AddAuthentication(AzureADB2CDefaults.BearerAuthenticationScheme)
.AddAzureADB2CBearer(options => Configuration.Bind("AzureAdB2C", options));
{{/IndividualB2CAuth}}
{{#mysql}}
services.AddMySqlConnection(Configuration);
{{/mysql}}
{{#actuator}}
{{#cloud-foundry}}
services.AddCloudFoundryActuators(Configuration);
{{/cloud-foundry}}
{{^cloud-foundry}}
services.AddAllActuators(Configuration);
{{/cloud-foundry}}
{{/actuator}}
{{#eureka-client}}
services.AddDiscoveryClient(Configuration);
{{/eureka-client}}
{{#postgresql}}
services.AddPostgresConnection(Configuration);
{{/postgresql}}
{{#amqp}}
services.AddRabbitMQConnection(Configuration);
{{/amqp}}
{{#data-redis}}
// Add the Redis distributed cache.
// We are using the Steeltoe Redis Connector to pickup the CloudFoundry
// Redis Service binding and use it to configure the underlying RedisCache
// This adds a IDistributedCache to the container
services.AddDistributedRedisCache(Configuration);
// This works like the above, but adds a IConnectionMultiplexer to the container
// services.AddRedisConnectionMultiplexer(Configuration);
{{/data-redis}}
{{#data-mongodb}}
services.AddMongoClient(Configuration);
{{/data-mongodb}}
{{#oauth}}
services.AddOAuthServiceOptions(Configuration);
{{/oauth}}
{{#mysql-efcore}}
services.AddDbContext<TestContext>(options => options.UseMySql(Configuration));
{{/mysql-efcore}}
{{#postgresql-efcore}}
services.AddDbContext<TestContext>(options => options.UseNpgsql(Configuration));
{{/postgresql-efcore}}
services.AddControllers();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
{{#RequiresHttps}}
else
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
{{/RequiresHttps}}
{{#Auth}}
app.UseAuthentication();
{{/Auth}}
{{#eureka-client}}
app.UseDiscoveryClient();
{{/eureka-client}}
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}

Просмотреть файл

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<gcServer enabled="true"/>
</runtime>
</configuration>

Просмотреть файл

@ -0,0 +1,14 @@
{
{{#placeholder}}
"ResolvedPlaceholderFromEnvVariables": "${PATH?NotFound}",
"UnresolvedPlaceholder": "${SomKeyNotFound?NotFound}",
"ResolvedPlaceholderFromJson": "${Logging:LogLevel:System?${Loggin:LogLevel:Default}}",
{{/placeholder}}
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}

Просмотреть файл

@ -1,7 +1,7 @@
description: Steeltoe 3.0.x, netcoreapp3.1, webapi, C#
constraints:
steeltoeVersionRange: 3.0.0
dotNetFrameworkRange: netcoreapp3.1
dotNetFrameworkRange: "[netcoreapp3.1,net5.0)"
dotNetTemplate: webapi
language: csharp
manifest: