Skip to content

Instantly share code, notes, and snippets.

View mirsaeedi's full-sized avatar

Ehsan Mirsaeedi mirsaeedi

  • Microsoft
  • Vancouver, Canada
  • 15:35 (UTC -08:00)
  • X @mirsaeedi
View GitHub Profile
lock(this);
lock("some string");
lock(this.publicField);
lock(typeof(MyType));
byte[] buffer = GetSomeBuffer();
byte[] digest = SHA256.HashData(buffer);
byte[] buffer = GetSomeBuffer();
using (var sha256 = SHA256.Create())
{
byte[] digest = sha256.ComputeHash(buffer);
/* use 'digest' here */
}
public class SearchEmployeeRequest
{
public string Name { get; set; }
public int MaxResults { get; set; }
}
public class SearchProductRequest
{
public string Name { get; set; }
public int MaxResults { get; set; }
public class SearchRequest
{
public string Name { get; set; }
public int MaxResults { get; set; }
// Product Specific Filters
public string Category { get; set; }
public int MaxPrice { get; set; }
public int Price { get; set; }
public class SearchRequest
{
public string Name { get; set; }
public int MaxResults { get; set; }
}
public class SearchEmployeeRequest
{
public string Name { get; set; }
public int MaxResults { get; set; }
}
public class SearchProductRequest
{
public string Name { get; set; }
@mirsaeedi
mirsaeedi / LifetimeEventsHostedService.cs
Created January 19, 2021 04:11
ASP.NET Lifetime Event Handler
internal class LifetimeEventsHostedService : IHostedService
{
private readonly ILogger<LifetimeEventsHostedService> _logger;
private readonly IHostApplicationLifetime _appLifetime;
private readonly TelemetryClient _telemtryClient;
public LifetimeEventsHostedService(
ILogger<LifetimeEventsHostedService> logger,
IHostApplicationLifetime appLifetime,
TelemetryClient telemtryClient)
@mirsaeedi
mirsaeedi / Program.cs
Last active January 19, 2021 04:10
Register Hosted Service
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
@mirsaeedi
mirsaeedi / ExampleController.cs
Created January 19, 2021 01:26
Check If Request Is Valid
public async Task<ActionResult> GetExample([FromBody] ExampleRequest request)
{
if (!ModelState.IsValid)
{
// return the customized error
}
// Handle the request
}