Skip to content

Instantly share code, notes, and snippets.

View GeradeDev's full-sized avatar
🖖
Merging without reviewing.

Gerade Geldenhuys GeradeDev

🖖
Merging without reviewing.
View GitHub Profile
namespace HomeController
{
[ApiVersion("1.0", Deprecated = true)]
[Route("api/Values")]
public class HomeController : Controller
{
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "Value1 from Version 1", "value2 from Version 1" };
@GeradeDev
GeradeDev / service-ci.yml
Created January 22, 2020 09:13
Build pipeline Configuration
# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
- dev
pool:
vmImage: 'Ubuntu-16.04'
$packageName = Get-VstsInput -Name 'packageName' -Require
$maxIncrement = Get-VstsInput -Name 'maxIncrement' -Require
$pipelineVariable = Get-VstsInput -Name 'pipelineVariable' -Require
Write-Host "The Package in use is: " $packageName
Write-Host "The Max Increment version is: " $maxIncrement
#Add Package Source
Write-Host "Adding Nuget Package Source"
Register-PackageSource -Name NuGet -Location https://www.nuget.org/api/v2 -ProviderName NuGet
public static IServiceCollection AddRedis(this IServiceCollection services, IConfiguration configuration)
{
var redisCacheSettings = new RedisOptions();
configuration.GetSection(SectionName).Bind(redisCacheSettings);
services.AddSingleton(redisCacheSettings);
if (!redisCacheSettings.Enabled)
{
return services;
}
public class ResponseCacheService : IResponseCacheService
{
private readonly IDistributedCache _distributedCache;
public ResponseCacheService(IDistributedCache distributedCache)
{
_distributedCache = distributedCache;
}
public async Task CacheResponseAsync(string cacheKey, object response, TimeSpan timeTimeLive)
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public class CachedAttribute : Attribute, IAsyncActionFilter
{
private readonly int _timeToLiveSeconds;
public CachedAttribute(int timeToLiveSeconds)
{
_timeToLiveSeconds = timeToLiveSeconds;
}
COPY *.csproj .
RUN dotnet restore
# Copy everything else and build
COPY . .
RUN dotnet publish -c Release -o out
public static IServiceCollection AddConsul(this IServiceCollection serviceCollection)
{
IConfiguration configuration;
using (var serviceProvider = serviceCollection.BuildServiceProvider())
{
configuration = serviceProvider.GetService<IConfiguration>();
}
ConsulOptions consulConfigOptions = configuration.GetOptions<ConsulOptions>("Consul");
serviceCollection.Configure<ConsulOptions>(configuration.GetSection("Consul"));
public class ConsulHttpClient : IConsulHttpClient
{
private readonly HttpClient _client;
private IConsulClient _consulclient;
public ConsulHttpClient(HttpClient client, IConsulClient consulclient)
{
_client = client;
_consulclient = consulclient;
}
[HttpGet("{customerid}")]
[Cached(Constants.Day_In_Seconds)]
public async Task<IActionResult> GetCustomerBasket(Guid customerid)
{
var basket = await _consulHttpClient.GetAsync<BasketDto>("basket-service", $"/basket/{customerid}");
return Ok(basket);
}