Skip to content

Instantly share code, notes, and snippets.

View alistairjevans's full-sized avatar

Alistair Evans alistairjevans

View GitHub Profile
@alistairjevans
alistairjevans / CovariantTest.cs
Created July 30, 2021 06:02
CovariantTestFailure
using Xunit;
namespace Autofac.Test.Features.OpenGenerics
{
public class OpenGenericCovariantTests
{
private interface INotificationHandler<TNotification>
{
}
@alistairjevans
alistairjevans / interfacedifferentdefault.cs
Created May 15, 2020 12:42
Default parameters on interfaces.
// 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 April 17, 2020 11:31
Complete Example Package Loader
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;
@alistairjevans
alistairjevans / nugetloader.packageid.cs
Created April 17, 2020 08:06
Package Identity Function
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)
{
/// <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; }
}
// 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;
// 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 February 19, 2020 12:49
Single Registration Protections
using Autofac;
using Autofac.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using Xunit;
namespace PreventDuplicateSingletons
{
// 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
{
"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"