1 | using Microsoft.AspNetCore.Builder;
|
---|
2 | using Microsoft.AspNetCore.Hosting;
|
---|
3 | using Microsoft.AspNetCore.SpaServices.AngularCli;
|
---|
4 | using Microsoft.Extensions.Configuration;
|
---|
5 | using Microsoft.Extensions.DependencyInjection;
|
---|
6 | using Microsoft.Extensions.Hosting;
|
---|
7 | using FarmatikoData;
|
---|
8 | using Microsoft.EntityFrameworkCore;
|
---|
9 | using FarmatikoServices;
|
---|
10 | using FarmatikoData.FarmatikoRepoInterfaces;
|
---|
11 | using FarmatikoData.FarmatikoRepo;
|
---|
12 | using FarmatikoServices.FarmatikoServiceInterfaces;
|
---|
13 | using FarmatikoServices.Services;
|
---|
14 | using Microsoft.Extensions.Logging;
|
---|
15 |
|
---|
16 | namespace Farmatiko
|
---|
17 | {
|
---|
18 | public class Startup
|
---|
19 | {
|
---|
20 | readonly string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
|
---|
21 |
|
---|
22 | public Startup(IConfiguration configuration)
|
---|
23 | {
|
---|
24 | Configuration = configuration;
|
---|
25 | }
|
---|
26 |
|
---|
27 | public IConfiguration Configuration { get; }
|
---|
28 |
|
---|
29 | // This method gets called by the runtime. Use this method to add services to the container.
|
---|
30 | public void ConfigureServices(IServiceCollection services)
|
---|
31 | {
|
---|
32 | services.AddCors(options =>
|
---|
33 | {
|
---|
34 | options.AddPolicy(name: MyAllowSpecificOrigins,
|
---|
35 | builder =>
|
---|
36 | {
|
---|
37 | builder.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin();
|
---|
38 | });
|
---|
39 | });
|
---|
40 |
|
---|
41 | services.AddControllersWithViews();
|
---|
42 | // In production, the Angular files will be served from this directory
|
---|
43 | services.AddSpaStaticFiles(configuration =>
|
---|
44 | {
|
---|
45 | configuration.RootPath = "ClientApp/dist";
|
---|
46 | });
|
---|
47 | var connectionString = Configuration.GetSection("ConnectionStrings").GetValue<string>("FarmatikoConnection");
|
---|
48 | services.AddEntityFrameworkNpgsql().AddDbContext<FarmatikoDataContext>(opt => opt.UseNpgsql(connectionString));
|
---|
49 |
|
---|
50 | services.AddTransient<IHealthFacilityRepository, HealthFacilityRepository>();
|
---|
51 | services.AddTransient<IHealthFacilityService, HealthFacilityService>();
|
---|
52 |
|
---|
53 | services.AddTransient<IHealthcareWorkerRepository, HealthcareWorkerRepository>();
|
---|
54 | services.AddTransient<IHealthcareWorkerService, HealthcareWorkerService>();
|
---|
55 |
|
---|
56 | services.AddTransient<IMedicineRepository, MedicineRepository>();
|
---|
57 | services.AddTransient<IMedicineService, MedicineService>();
|
---|
58 |
|
---|
59 | services.AddTransient<IMedicineListRepository, MedicineListRepository>();
|
---|
60 | services.AddTransient<IMedicineListService, MedicineListService>();
|
---|
61 |
|
---|
62 | services.AddTransient<IPandemicRepository, PandemicRepository>();
|
---|
63 | services.AddTransient<IPandemicService, PandemicService>();
|
---|
64 |
|
---|
65 | services.AddTransient<IPharmacyHeadRepository, PharmacyHeadRepository>();
|
---|
66 | services.AddTransient<IPharmacyHeadService, PharmacyHeadService>();
|
---|
67 |
|
---|
68 | services.AddTransient<IPharmacyRepository, PharmacyRepository>();
|
---|
69 | services.AddTransient<IPharmacyService, PharmacyService>();
|
---|
70 |
|
---|
71 | services.AddTransient<IProcessJSONService, ProcessJSONService>();
|
---|
72 |
|
---|
73 | services.AddTransient<ILogger, Logger<ProcessJSONService>>();
|
---|
74 | }
|
---|
75 |
|
---|
76 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
---|
77 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
---|
78 | {
|
---|
79 | if (env.IsDevelopment())
|
---|
80 | {
|
---|
81 | app.UseDeveloperExceptionPage();
|
---|
82 | }
|
---|
83 | else
|
---|
84 | {
|
---|
85 | app.UseExceptionHandler("/Error");
|
---|
86 | // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
---|
87 | app.UseHsts();
|
---|
88 | }
|
---|
89 |
|
---|
90 | app.UseHttpsRedirection();
|
---|
91 | app.UseStaticFiles();
|
---|
92 | if (!env.IsDevelopment())
|
---|
93 | {
|
---|
94 | app.UseSpaStaticFiles();
|
---|
95 | }
|
---|
96 |
|
---|
97 | app.UseRouting();
|
---|
98 |
|
---|
99 | app.UseCors(MyAllowSpecificOrigins);
|
---|
100 |
|
---|
101 | app.UseEndpoints(endpoints =>
|
---|
102 | {
|
---|
103 | endpoints.MapControllerRoute(
|
---|
104 | name: "default",
|
---|
105 | pattern: "{controller}/{action=Index}/{id?}");
|
---|
106 | });
|
---|
107 |
|
---|
108 | app.UseSpa(spa =>
|
---|
109 | {
|
---|
110 | // To learn more about options for serving an Angular SPA from ASP.NET Core,
|
---|
111 | // see https://go.microsoft.com/fwlink/?linkid=864501
|
---|
112 |
|
---|
113 | spa.Options.SourcePath = "ClientApp";
|
---|
114 |
|
---|
115 | if (env.IsDevelopment())
|
---|
116 | {
|
---|
117 | spa.UseAngularCliServer(npmScript: "start");
|
---|
118 | }
|
---|
119 | });
|
---|
120 | }
|
---|
121 | }
|
---|
122 | }
|
---|