This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Threading; | |
| using System.Threading.Tasks; | |
| using Microsoft.Extensions.Logging; | |
| namespace SchedulerJobSample.Worker | |
| { | |
| public interface IScopedSchedulerService | |
| { | |
| Task ExecuteAsync(CancellationToken cancellationToken); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Threading; | |
| using System.Threading.Tasks; | |
| using Cronos; | |
| using Microsoft.Extensions.Hosting; | |
| using Microsoft.Extensions.Logging; | |
| namespace SchedulerJobSample.Worker | |
| { | |
| public class SchedulerService : BackgroundService |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Threading; | |
| using System.Threading.Tasks; | |
| using Microsoft.Extensions.Hosting; | |
| using Microsoft.Extensions.Logging; | |
| namespace SchedulerJobSample.Worker | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Startup | |
| { | |
| public virtual void ConfigureServices(IServiceCollection services) | |
| { | |
| services.AddHttpClient<IMyServiceClient, MyServiceClient>((serviceProvider, client) => | |
| { | |
| client.BaseAddress = customerCoreServiceOptions.BaseUri; | |
| client.DefaultRequestHeaders.Add("correlation-id", | |
| CorrelationIdContext.GetCorrelationId() ?? | |
| Guid.NewGuid().ToString()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class CorrelationIdMiddleware | |
| { | |
| private readonly RequestDelegate _next; | |
| public CorrelationIdMiddleware(RequestDelegate next) | |
| { | |
| _next = next; | |
| } | |
| public async Task Invoke(HttpContext context) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class CorrelationIdContext | |
| { | |
| private static readonly AsyncLocal<string> _correlationId = new AsyncLocal<string>(); | |
| public static void SetCorrelationId(string correlationId) | |
| { | |
| if (string.IsNullOrWhiteSpace(correlationId) | |
| { | |
| throw new ArgumentException("Correlation Id cannot be null or empty", nameof(correlationId)); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Program | |
| { | |
| public static void Main() | |
| { | |
| dynamic data = new { SomeProperty = "ABC" }; | |
| var response = IsTrue(data); | |
| if (response == "1") | |
| { | |
| Console.WriteLine("How can this compile?"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public abstract class PaymentType : Enumeration | |
| { | |
| public static readonly PaymentType DebitCard = new DebitCardType(); | |
| public static readonly PaymentType CreditCard = new CreditCardType(); | |
| public abstract string Code { get; } | |
| protected PaymentType(int value, string name = null) : base(value, name) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protected PaymentType(int value, string name = null) : base(value, name) | |
| { | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public abstract class StatesPaymentType : PaymentType | |
| { | |
| public new static readonly PaymentType DebitCard = new DebitCardType(); | |
| public new static readonly PaymentType CreditCard = new CreditCardType(); | |
| public static readonly PaymentType Bitcoin = new BitCoinType(); | |
| private class BitCoinType : PaymentType | |
| { |