Skip to content

Instantly share code, notes, and snippets.

View PradeepLoganathan's full-sized avatar

Pradeep Loganathan PradeepLoganathan

View GitHub Profile
@PradeepLoganathan
PradeepLoganathan / dynamicregistration.cs
Created February 1, 2020 07:35
Dynamic registration of types using assembly scanning.
Assembly ConsoleAppAssembly = typeof(Program).Assembly;
var ConsoleAppTypes =
from type in ConsoleAppAssembly.GetTypes()
where !type.IsAbstract
where typeof(ICustomer).IsAssignableFrom(type)
select type;
foreach (var type in ConsoleAppTypes)
{
@PradeepLoganathan
PradeepLoganathan / ConsoleApplication.cs
Created February 1, 2020 07:26
constructor injection
using Injector.Abstractions;
using System;
using System.Collections.Generic;
using System.Text;
namespace Injector
{
class ConsoleApplication
{
private readonly ICustomer _customer;
static void Main(string[] args)
{
RegisterServices();
IServiceScope scope = _serviceProvider.CreateScope();
scope.ServiceProvider.GetRequiredService<ConsoleApplication>().Run();
DisposeServices();
}
@PradeepLoganathan
PradeepLoganathan / disposeservices.cs
Created February 1, 2020 07:19
Dispose services in the service container
private static void DisposeServices()
{
if (_serviceProvider == null)
{
return;
}
if (_serviceProvider is IDisposable)
{
((IDisposable)_serviceProvider).Dispose();
}
@PradeepLoganathan
PradeepLoganathan / Program.cs
Created February 1, 2020 01:45
Registering Services in the DI container
private static void RegisterServices()
{
var services = new ServiceCollection();
services.AddSingleton<ICustomer, Customer>();
services.AddSingleton<ConsoleApplication>();
_serviceProvider = services.BuildServiceProvider(true);
}
var section = Configuration.GetSection("Sectionofsettings");
var section = Configuration.GetValue("Onesetting");
@PradeepLoganathan
PradeepLoganathan / Program.cs
Created December 20, 2019 04:54
.net core console application - reading environmental variables
static async Task Main(string[] args)
{
IConfiguration Configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.AddCommandLine(args)
.Build();
}
@PradeepLoganathan
PradeepLoganathan / installpackage.cmd
Created December 20, 2019 04:51
Packages for configuration for a .net core console application
Install-Package Microsoft.Extensions.Configuration
Install-Package Microsoft.Extensions.Configuration.Json
Install-Package Microsoft.Extensions.Configuration.CommandLine
Install-Package Microsoft.Extensions.Configuration.EnvironmentVariables
@PradeepLoganathan
PradeepLoganathan / startup.cs
Created September 24, 2019 06:32
Using http2 using kestrel
public static IWebHostBuilder CreateWebHostBuilder(string[] args)
{
return WebHost.CreateDefaultBuilder(args)
.ConfigureKestrel(options =>
{
options.Listen(IPAddress.Any, 8080, listenOptions =>
{
listenOptions.Protocols = HttpProtocols.Http1AndHttp2;
listenOptions.UseHttps("testcertificate.pfx", "donotusepassword");
});
@PradeepLoganathan
PradeepLoganathan / SQSQueue.yml
Created August 6, 2019 23:13
Cloudformation template to create an SQS queue
Resources:
SQSQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: my-sqsqueue
Output:
SQSQueueURL:
Value: !Ref SQSQueue
Export: