Instantly share code, notes, and snippets.

View newSqlite.cs
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
var options = new DbContextOptionsBuilder<MyDbContext>()
.UseSqlite(connection)
.Options;
var dbContext = new MyDbContext(options);
dbContext.Database.EnsureCreated();
View newInMemory.cs
var options = new DbContextOptionsBuilder<MyDbContext>()
.UseInMemoryDatabase(databaseName: "Test")
// Don't raise the error warning us that the in memory db doesn't support transactions
.ConfigureWarnings(w => w.Ignore(InMemoryEventId.TransactionIgnoredWarning))
.Options;
var dbContext = new MyDbContext(options);
View dbContext.cs
public MyDbContext(string connectionString)
{
_connectionString = connectionString;
}
public MyDbContext(DbContextOptions<MyDbContext> options) : base(options) { }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (optionsBuilder.IsConfigured == false)
View module.cs
using System.Threading;
using System.Threading.Tasks;
using Nancy;
public class DemoModule: NancyV1Module
{
public DemoModule()
{
Get["named", "/sync"] = DoSync;
Get["/sync/noname"] = DoSync;
View NancyV1Module.cs
using System;
using System.Threading;
using System.Threading.Tasks;
using Nancy;
public class NancyV1Module : NancyModule
{
public NancyV1RouteBuilder Get => new NancyV1RouteBuilder(this, NancyV1RouteBuilder.HttpMethod.Get);
public NancyV1RouteBuilder Put => new NancyV1RouteBuilder(this, NancyV1RouteBuilder.HttpMethod.Put);
public NancyV1RouteBuilder Post => new NancyV1RouteBuilder(this, NancyV1RouteBuilder.HttpMethod.Post);
View nancy.cs
public class ProductsModule : NancyModule
{
public ProductsModule()
{
Get["/products/{id}", runAsync: true] = async (_, token) =>
{
//do something long and tedious
};
}
}
View dependsOn.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using Newtonsoft.Json;
using static Bullseye.Targets;
namespace bulltest
{
class Program
View defaultTask.cs
using System;
using static Bullseye.Targets;
namespace bulltest
{
class Program
{
static void Main(string[] args)
{
Target("default", () => {
View csproj.xml
<PropertyGroup>
<Product>Microsoft ASP.NET Core MVC</Product>
<RepositoryUrl>https://github.com/aspnet/Mvc</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<RepositoryRoot>$(MSBuildThisFileDirectory)</RepositoryRoot>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)build\Key.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<AssemblySigningCertName>Microsoft</AssemblySigningCertName>
<PackageSigningCertName>MicrosoftNuGet</PackageSigningCertName>
<PublicSign Condition="'$(OS)' != 'Windows_NT'">true</PublicSign>
View program.cs
using System;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
namespace Demo
{
public class Program
{
public static void Main(string[] args)
{