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