Skip to content

Instantly share code, notes, and snippets.

View bayological's full-sized avatar
🎯
Focusing

Bayological bayological

🎯
Focusing
View GitHub Profile
@bayological
bayological / 0_reuse_code.js
Created June 4, 2017 00:51
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@bayological
bayological / DependencyExtensions.cs
Last active September 13, 2018 15:09
Extension method to get the specific registered type
public static IServiceCollection Named<TService, TImplementation>(this IServiceCollection services, string name)
{
var implementationToBeNamed = services.FirstOrDefault(s => s.ImplementationType == typeof(TImplementation) &&
s.ServiceType == typeof(TService));
return services;
}
@bayological
bayological / animals.cs
Created September 28, 2018 01:03
Animal classes and interfaces
namespace LongRunningApp.Animals
{
public interface ICow
{
void Speak();
}
public class Cow : ICow
{
public void Speak()
@bayological
bayological / application.cs
Last active September 28, 2018 01:27
Application class with animal types
public class Application : IApplication
{
private readonly ICat _cat;
private readonly ICow _cow;
private readonly IMouse _mouse;
public Application(ICat cat, ICow cow, IMouse mouse)
{
_cat = cat;
_mouse = mouse;
@bayological
bayological / speak.cs
Last active September 28, 2018 01:16
Speaking animals work method
private async Task WorkAsync()
{
while (true)
{
Console.WriteLine("The animals will now speak...");
_cow.Speak();
_cat.Speak();
_mouse.Speak();
Thread.Sleep(TimeSpan.FromSeconds(3));
}
@bayological
bayological / registrations.cs
Created September 28, 2018 01:33
Registering types manually without Scrutor
services.AddTransient<ICow, Cow>();
services.AddTransient<IMouse, Mouse>();
services.AddTransient<ICat, Cat>();
@bayological
bayological / registration.cs
Created September 28, 2018 02:02
Type registration with Scurtor
public static void Run(IServiceCollection services)
{
services.Scan(scan => scan
.FromAssemblyOf<ICat>()
.AddClasses()
.AsImplementedInterfaces()
.WithTransientLifetime());
services.AddSingleton<IApplication, Application>();
}
@bayological
bayological / RegistrationsInNamespace.cs
Created September 28, 2018 23:06
Registration of classes in the same namespace as ICat
public static void Run(IServiceCollection services)
{
services.Scan(scan => scan
.FromAssemblyOf<ICat>()
.AddClasses(classes => classes.InNamespaceOf<ICat>())
.AsImplementedInterfaces()
.WithTransientLifetime());
services.AddSingleton<IApplication, Application>();
}
@bayological
bayological / gist:801b184dbda862d8c3e9613db353599f
Created October 1, 2018 15:54
Publishing a self contained .Net Core app targeting Windows x64
dotnet publish --runtime win10-x64 -o C:\TestPublish -f netcoreapp2.0 -c debug
@bayological
bayological / AzureCreds.cs
Created April 8, 2019 18:24
Azure credential variables
private static string _subscriptionId = "";
private static string _clientId = "";
private static string _clientSecret = "";
private static string _tenantId = "";