Skip to content

Instantly share code, notes, and snippets.

@crgrieve
crgrieve / Program.cs
Last active Sep 3, 2021
C#10 filescoped namespace
View Program.cs
namespace Umbracov9DotNet6;
public class Program
{
public static void Main(string[] args)
=> CreateHostBuilder(args)
.Build()
.Run();
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
@crgrieve
crgrieve / Startup.cs
Created Sep 3, 2021
C#9 API Startup.cs
View Startup.cs
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
using System;
@crgrieve
crgrieve / Program.cs
Created Sep 3, 2021
C#9 API Program.cs
View Program.cs
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace dotnet5API
@crgrieve
crgrieve / Program.cs
Created Sep 3, 2021
C#10 API program.cs
View Program.cs
using Microsoft.OpenApi.Models;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new() { Title = "dotnet6PreviewAPI", Version = "v1" });
@crgrieve
crgrieve / appSettings.Development.json
Created Jul 23, 2021
Example appsettings.json for Umbraco v9
View appSettings.Development.json
{
"$schema": "./umbraco/config/appsettings-schema.json",
"Serilog": {
"MinimumLevel": {
"Default": "Information"
},
"Umbraco": {
"CMS": {
"Content": {
"MacroErrors": "Throw"
@crgrieve
crgrieve / Startup.cs
Last active Jul 2, 2021
An example Startup.cs for Umbraco v9 project with some usings refactored to a global file.
View Startup.cs
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Extensions;
namespace DotNet6Umbraco
{
public class Startup
{
@crgrieve
crgrieve / Program.cs
Created Jul 2, 2021
An example Program.cs for Umbraco v9 project with usings refactored to a global file.
View Program.cs
namespace DotNet6Umbraco
{
public class Program
{
public static void Main(string[] args)
=> CreateHostBuilder(args)
.Build()
.Run();
public static IHostBuilder CreateHostBuilder(string[] args) =>
View Usings.cs
global using System;
global using Microsoft.AspNetCore.Hosting;
global using Microsoft.Extensions.Hosting;
global using Microsoft.Extensions.Logging;
@crgrieve
crgrieve / BlogPostModel
Created Apr 6, 2021
A model class to return from our API contoller
View BlogPostModel
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Umbracov9AlphaAPIs.APIModels
{
public class BlogPostModel
{
public string Title { get; init; }
@crgrieve
crgrieve / BlogController.cs
Created Apr 6, 2021
Umbraco dotnet core API controller with annotations
View BlogController.cs
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using Umbraco.Cms.Core;
using Umbraco.Cms.Web.Common.Controllers;
using Umbraco.Extensions;
using Umbracov9AlphaAPIs.APIModels;
namespace Umbracov9AlphaAPIs.Controllers
{
[ApiController]