Skip to content

Instantly share code, notes, and snippets.

View DatabaseFileProvider.cs
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Primitives;
using System;
using System.IO;
namespace RazorEngineViewOptionsFileProviders
{
public class DatabaseFileProvider : IFileProvider
{
private string _connection;
View DatabaseFileInfo.cs
using Microsoft.Extensions.FileProviders;
using System;
using System.Data.SqlClient;
using System.IO;
using System.Text;
namespace RazorEngineViewOptionsFileProviders
{
public class DatabaseFileInfo : IFileInfo
{
View DatabaseChangeToken.cs
using Microsoft.Extensions.Primitives;
using System;
using System.Data.SqlClient;
namespace RazorEngineViewOptionsFileProviders
{
public class DatabaseChangeToken : IChangeToken
{
private string _connection;
private string _viewPath;
View RazorEngineViewOptionsFileProviders.Startup.cs
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
services.Configure<RazorViewEngineOptions>(opts =>
opts.FileProviders.Add(
new DatabaseFileProvider(Configuration.GetConnectionString("DefaultConnection"))
)
);
}
View HomeController.cs
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
namespace IHostingEnvironmentExample.Controllers
{
public class HomeController : Controller
{
private IHostingEnvironment _env;
public HomeController(IHostingEnvironment env)
{
View Program.cs
using Microsoft.AspNetCore.Hosting;
using System.IO;
namespace IHostingEnvironmentExample
{
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
View tsconfig.json
{
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"target": "es5"
},
"exclude": [
"node_modules",
View tsconfig.json
{
"compileOnSave": true,
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"module": "amd",
"target": "es5"
}
View webmail.json
{
"folders": [
{
"id": "Inbox",
"mails": [
{
"id": 1,
"from": "Abbot \u003coliver@smoke-stage.xyz\u003e",
"to": "steve@example.com",
"date": "May 25, 2011",
View tsconfig.json
{
"compileOnSave": true,
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"target": "es6",
"module": "amd"
},