Skip to content
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
93 lines (80 sloc) 3.9 KB
using System.IO;
using System.Reflection;
using DataLayer.EfCode;
using GenericServices.Setup;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using ServiceLayer.HomeController.Dtos;
namespace RazorPageApp
public class Startup
public Startup(IConfiguration configuration)
Configuration = configuration;
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
// thanks to
services.AddMvc().AddRazorPagesOptions(options =>
options.Conventions.AddPageRoute("/Home/Index", "");
//var connection = Configuration.GetConnectionString("DefaultConnection");
//Swapped over to sqlite in-memory database
var connectionStringBuilder = new SqliteConnectionStringBuilder { DataSource = ":memory:" };
var connectionString = connectionStringBuilder.ToString();
var connection = new SqliteConnection(connectionString);
connection.Open(); //see
services.AddDbContext<EfCoreContext>(options => options.UseSqlite(connection));
//This is the version you would use if you were registering multiple DbContext
//services.ConfigureGenericServicesEntities(typeof(BookDbContext), typeof(OrderDbContext))
// .ScanAssemblesForDtos(Assembly.GetAssembly(typeof(BookListDto)))
// .RegisterGenericServices();
//I removed the code below, as this was only needed for the hand-coded versions of the services
////Now I use AutoFac to do some of the more complex registering of services
//var containerBuilder = new ContainerBuilder();
////Now I use the ServiceLayer AutoFac module that registers all the other DI items, such as my biz logic
//containerBuilder.RegisterModule(new ServiceLayerModule());
//var container = containerBuilder.Build();
//return new AutofacServiceProvider(container);
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
if (env.IsDevelopment())
// thanks to for this trick
if (env.IsDevelopment())
app.UseStaticFiles(new StaticFileOptions()
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), @"node_modules")),
RequestPath = new PathString("/vendor")
You can’t perform that action at this time.