Skip to content

Instantly share code, notes, and snippets.

Avatar

Alistair Evans alistairjevans

View GitHub Profile
@alistairjevans
alistairjevans / interfacedifferentdefault.cs
Created May 15, 2020
Default parameters on interfaces.
View interfacedifferentdefault.cs
// Default arguments in interfaces.
// If you call the interface method, the passed value will be "interface".
// If you call the object method, the passed value will be "method".
// Should the compiler error?
public interface IPipelineBuilder
{
void AddStage(IPipelineStage stage, string mode = "interface");
}
@alistairjevans
alistairjevans / nugetpackageload.cs
Created Apr 17, 2020
Complete Example Package Loader
View nugetpackageload.cs
using AutoStep.Extensions;
using Microsoft.Extensions.DependencyModel;
using NuGet.Common;
using NuGet.Configuration;
using NuGet.Frameworks;
using NuGet.Packaging;
using NuGet.Packaging.Core;
using NuGet.Packaging.Signing;
using NuGet.Protocol.Core.Types;
using NuGet.Resolver;
View nugetloader.packageid.cs
private async Task<PackageIdentity> GetPackageIdentity(
ExtensionConfiguration extConfig, SourceCacheContext cache, ILogger nugetLogger,
IEnumerable<SourceRepository> repositories, CancellationToken cancelToken)
{
// Go through each repository.
// If a repository contains only pre-release packages (e.g. AutoStep CI), and
// the configuration doesn't permit pre-release versions,
// the search will look at other ones (e.g. NuGet).
foreach (var sourceRepository in repositories)
{
View nugetloader.cs
/// <summary>
/// Represents the configuration for a single extension to install.
/// </summary>
public class ExtensionConfiguration
{
public string Package { get; set; }
public string Version { get; set; }
public bool PreRelease { get; set; }
}
View backgroundwithconstructor.cs
// Riffing on https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-3.1&tabs=visual-studio
public class TimedHostedService : IHostedService, IDisposable
{
private readonly ILogger<TimedHostedService> _logger;
private readonly IServiceProvider _provider;
private Timer _timer;
public TimedHostedService(IServiceProvider provider, ILogger<TimedHostedService> logger)
{
_provider = provider;
View background.cs
// Riffing on https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-3.1&tabs=visual-studio
public class TimedHostedService : IHostedService, IDisposable
{
private readonly ILogger<TimedHostedService> _logger;
private readonly IServiceProvider _provider;
private Timer _timer;
public TimedHostedService(IServiceProvider provider, ILogger<TimedHostedService> logger)
{
_provider = provider;
@alistairjevans
alistairjevans / test.cs
Created Feb 19, 2020
Single Registration Protections
View test.cs
using Autofac;
using Autofac.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using Xunit;
namespace PreventDuplicateSingletons
{
View linetokeniser.g4
// This parser rule is only used for line tokenisation
// it doesn't natively understand more context than a single line.
// It is also more forgiving than the normal parser.
onlyLine: WS? TAG lineTerm #lineTag
| WS? OPTION lineTerm #lineOpt
| WS? STEP_DEFINE DEF_WS? stepDeclaration? lineTerm #lineStepDefine
| WS? FEATURE WS? text? lineTerm #lineFeature
| WS? BACKGROUND lineTerm #lineBackground
| WS? SCENARIO WS? text? lineTerm #lineScenario
| WS? SCENARIO_OUTLINE WS? text? lineTerm #lineScenarioOutline
View package.json
{
"name": "monaco-blazor-editor",
"version": "1.0.0",
"description": "",
"private": true,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build-dev": "npx webpack --config webpack.dev.js",
"build": "npx webpack --config webpack.dev.js",
"build-prod": "npx webpack --config webpack.prod.js"
@alistairjevans
alistairjevans / autofac-changes.md
Last active Jan 22, 2020
Autofac Changes for 5.0
View autofac-changes.md

Autofac Changes in 5.0

Framework Version Targeting Changes

From Autofac 5, we will no longer provide a target for .NET 4.5. The minimum version of .NET Framework you can use Autofac with is .NET 4.6.1.

The full targeting list is now:

  • netstandard2.1
You can’t perform that action at this time.