source: Farmatiko/Startup.cs@ c406ae5

Last change on this file since c406ae5 was c406ae5, checked in by DimitarSlezenkovski <dslezenkovski@…>, 2 years ago

Update Models, Repos, Services and Controllers

  • Property mode set to 100644
File size: 4.6 KB
Line 
1using Microsoft.AspNetCore.Builder;
2using Microsoft.AspNetCore.Hosting;
3using Microsoft.AspNetCore.SpaServices.AngularCli;
4using Microsoft.Extensions.Configuration;
5using Microsoft.Extensions.DependencyInjection;
6using Microsoft.Extensions.Hosting;
7using FarmatikoData;
8using Microsoft.EntityFrameworkCore;
9using FarmatikoServices;
10using FarmatikoData.FarmatikoRepoInterfaces;
11using FarmatikoData.FarmatikoRepo;
12using FarmatikoServices.FarmatikoServiceInterfaces;
13using FarmatikoServices.Services;
14using Microsoft.Extensions.Logging;
15
16namespace 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}
Note: See TracBrowser for help on using the repository browser.