source: Farmatiko/Startup.cs@ ef1219a

Last change on this file since ef1219a was d2e69be, checked in by DimitarSlezenkovski <dslezenkovski@…>, 4 years ago

Add Route Attribute

  • Property mode set to 100644
File size: 2.9 KB
Line 
1using Microsoft.AspNetCore.Builder;
2using Microsoft.AspNetCore.Hosting;
3using Microsoft.AspNetCore.HttpsPolicy;
4using Microsoft.AspNetCore.SpaServices.AngularCli;
5using Microsoft.Extensions.Configuration;
6using Microsoft.Extensions.DependencyInjection;
7using Microsoft.Extensions.Hosting;
8using FarmatikoData;
9using Microsoft.EntityFrameworkCore;
10using FarmatikoServices;
11using FarmatikoData.FarmatikoRepoInterfaces;
12using FarmatikoData.FarmatikoRepo;
13
14namespace Farmatiko
15{
16 public class Startup
17 {
18 public Startup(IConfiguration configuration)
19 {
20 Configuration = configuration;
21 }
22
23 public IConfiguration Configuration { get; }
24
25 // This method gets called by the runtime. Use this method to add services to the container.
26 public void ConfigureServices(IServiceCollection services)
27 {
28 services.AddControllersWithViews();
29 // In production, the Angular files will be served from this directory
30 services.AddSpaStaticFiles(configuration =>
31 {
32 configuration.RootPath = "ClientApp/dist";
33 });
34 var connectionString = Configuration.GetSection("ConnectionStrings").GetValue<string>("FarmatikoConnection");
35 services.AddEntityFrameworkNpgsql().AddDbContext<FarmatikoDataContext>(opt => opt.UseNpgsql(connectionString));
36
37 services.AddTransient<IHealthFacilityRepository, HealthFacilityRepository>();
38 services.AddTransient<IHealthFacilityService, HealthFacilityService>();
39 }
40
41 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
42 public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
43 {
44 if (env.IsDevelopment())
45 {
46 app.UseDeveloperExceptionPage();
47 }
48 else
49 {
50 app.UseExceptionHandler("/Error");
51 // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
52 app.UseHsts();
53 }
54
55 app.UseHttpsRedirection();
56 app.UseStaticFiles();
57 if (!env.IsDevelopment())
58 {
59 app.UseSpaStaticFiles();
60 }
61
62 app.UseRouting();
63
64 app.UseEndpoints(endpoints =>
65 {
66 endpoints.MapControllerRoute(
67 name: "default",
68 pattern: "{controller}/{action=Index}/{id?}");
69 });
70
71 app.UseSpa(spa =>
72 {
73 // To learn more about options for serving an Angular SPA from ASP.NET Core,
74 // see https://go.microsoft.com/fwlink/?linkid=864501
75
76 spa.Options.SourcePath = "ClientApp";
77
78 if (env.IsDevelopment())
79 {
80 spa.UseAngularCliServer(npmScript: "start");
81 }
82 });
83 }
84 }
85}
Note: See TracBrowser for help on using the repository browser.