Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Microservices, Azure, Containers, Kubernetes, Infrastructure, Polyglot, etc

rahul sahay rahulsahay19

💭
Microservices, Azure, Containers, Kubernetes, Infrastructure, Polyglot, etc
View GitHub Profile
View program.cs
internal class Program
{
public static async Task Main(string[] args)
{
LinkedInProfile linkedInProfile = new LinkedInProfile();
try
{
await linkedInProfile.GetProfileWithoutAsync();
}
catch (Exception e)
View LinkedInProfile.cs
public class LinkedInProfile
{
private readonly HttpClient _httpClient = new HttpClient();
private readonly string _linkedInProfile = "https://www.linkedin.com/in/rahulsahay19/";
public async Task<string> GetProfileUsingAsync()
{
return await _httpClient.GetStringAsync(_linkedInProfile);
}
View Policies.cs
private static IAsyncPolicy<HttpResponseMessage> GetRetryPolicy()
{
return HttpPolicyExtensions.HandleTransientHttpError()
.WaitAndRetryAsync(5,
retryAttempt => TimeSpan.FromMilliseconds(Math.Pow(2, retryAttempt) * 1000),
(_, waitingTime) =>
{
Console.WriteLine("Retrying.....");
});
}
View polly.cs
services.AddHttpClient<IDiscountService, DiscountService>(c =>
c.BaseAddress = new Uri(Configuration["ApiConfigs:Discount:Uri"]))
.AddPolicyHandler(GetRetryPolicy())
.AddPolicyHandler(GetCircuitBreakerPolicy());
View httpClient.cs
using BookMyEvent.Services.ShoppingCart.DTOs;
using BookMyEvent.Services.ShoppingCart.Extensions;
using System;
using System.Net.Http;
using System.Threading.Tasks;
namespace BookMyEvent.Services.ShoppingCart.Services
{
public class DiscountService : IDiscountService
{
View AddHttpClient.cs
services.AddHttpClient<IDiscountService, DiscountService>(c =>
c.BaseAddress = new Uri(Configuration["ApiConfigs:Discount:Uri"]))
View program.cs
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Movies.Infrastructure.Data;
namespace Movies.API
{
View MovieController.cs
using System.Collections.Generic;
using System.Threading.Tasks;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Movies.Application.Commands;
using Movies.Application.Queries;
using Movies.Application.Responses;
namespace Movies.API.Controllers
View ApiController.cs
using Microsoft.AspNetCore.Mvc;
namespace Movies.API.Controllers
{
[ApiVersion("1")]
[Route("api/v{version:apiVersion}/[controller]")]
[ApiController]
public class ApiController : ControllerBase
{
}
View appsettings.json
{
"ConnectionStrings": {
"MovieConnection": "Server=localhost,1445;Database=MovieDb;User Id=sa;Password=Docker@1;"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}