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
| // Use Gists to store code you would like to remember later on | |
| console.log(window); // log the "window" object to the console |
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 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; | |
| } |
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
| namespace LongRunningApp.Animals | |
| { | |
| public interface ICow | |
| { | |
| void Speak(); | |
| } | |
| public class Cow : ICow | |
| { | |
| public void Speak() |
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 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; |
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
| private async Task WorkAsync() | |
| { | |
| while (true) | |
| { | |
| Console.WriteLine("The animals will now speak..."); | |
| _cow.Speak(); | |
| _cat.Speak(); | |
| _mouse.Speak(); | |
| Thread.Sleep(TimeSpan.FromSeconds(3)); | |
| } |
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
| services.AddTransient<ICow, Cow>(); | |
| services.AddTransient<IMouse, Mouse>(); | |
| services.AddTransient<ICat, Cat>(); |
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 static void Run(IServiceCollection services) | |
| { | |
| services.Scan(scan => scan | |
| .FromAssemblyOf<ICat>() | |
| .AddClasses() | |
| .AsImplementedInterfaces() | |
| .WithTransientLifetime()); | |
| services.AddSingleton<IApplication, Application>(); | |
| } |
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 static void Run(IServiceCollection services) | |
| { | |
| services.Scan(scan => scan | |
| .FromAssemblyOf<ICat>() | |
| .AddClasses(classes => classes.InNamespaceOf<ICat>()) | |
| .AsImplementedInterfaces() | |
| .WithTransientLifetime()); | |
| services.AddSingleton<IApplication, Application>(); | |
| } |
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
| dotnet publish --runtime win10-x64 -o C:\TestPublish -f netcoreapp2.0 -c debug |
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
| private static string _subscriptionId = ""; | |
| private static string _clientId = ""; | |
| private static string _clientSecret = ""; | |
| private static string _tenantId = ""; |
OlderNewer