Last active
November 23, 2017 20:57
-
-
Save gistlyn/956a1c5cb7a13240daa7f1ea00ab8881 to your computer and use it in GitHub Desktop.
.NET Core RazorRockstars Startup.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using Funq; | |
| using Microsoft.AspNetCore.Builder; | |
| using Microsoft.AspNetCore.Hosting; | |
| using Microsoft.Extensions.Configuration; | |
| using Microsoft.Extensions.DependencyInjection; | |
| using Microsoft.Extensions.Logging; | |
| using ServiceStack; | |
| using ServiceStack.Data; | |
| using ServiceStack.Host.Handlers; | |
| using ServiceStack.Logging; | |
| using ServiceStack.Mvc; | |
| using ServiceStack.OrmLite; | |
| using ServiceStack.Configuration; | |
| namespace RazorRockstars.WebHost | |
| { | |
| 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) | |
| { | |
| services.AddMvc(); | |
| } | |
| // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | |
| public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) | |
| { | |
| if (env.IsDevelopment()) | |
| { | |
| app.UseDeveloperExceptionPage(); | |
| app.UseBrowserLink(); | |
| } | |
| else | |
| { | |
| app.UseExceptionHandler("/Home/Error"); | |
| } | |
| app.UseStaticFiles(); | |
| app.UseServiceStack(new AppHost { | |
| AppSettings = new NetCoreAppSettings(Configuration) | |
| }); | |
| app.UseMvc(routes => | |
| { | |
| routes.MapRoute( | |
| name: "default", | |
| template: "{controller=Home}/{action=Index}/{id?}"); | |
| }); | |
| app.Use(new RazorHandler("/notfound")); | |
| //Other examples of using built-in ServiceStack Handlers as middleware | |
| //app.Use(new StaticFileHandler("wwwroot/img/react-logo.png").Middleware); | |
| //app.Use(new RequestInfoHandler().Middleware); | |
| } | |
| } | |
| public class AppHost : AppHostBase | |
| { | |
| public AppHost() : base("Test Razor", typeof(AppHost).Assembly) { } | |
| public override void Configure(Container container) | |
| { | |
| SetConfig(new HostConfig { DebugMode = true }); | |
| Plugins.Add(new RazorFormat()); | |
| container.Register<IDbConnectionFactory>( | |
| new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider)); | |
| using (var db = container.Resolve<IDbConnectionFactory>().Open()) | |
| { | |
| db.CreateTableIfNotExists<Rockstar>(); | |
| db.InsertAll(RockstarsService.SeedData); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment