source: Farmatiko/Startup.cs@ d8fafb8

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

Update & add service

  • Property mode set to 100644
File size: 4.5 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;
14
15namespace Farmatiko
16{
17 public class Startup
18 {
19 readonly string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
20
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 {
31 services.AddCors(options =>
32 {
33 options.AddPolicy(name: MyAllowSpecificOrigins,
34 builder =>
35 {
36 builder.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin();
37 });
38 });
39
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
49 services.AddTransient<IHealthFacilityRepository, HealthFacilityRepository>();
50 services.AddTransient<IHealthFacilityService, HealthFacilityService>();
51
52 services.AddTransient<IHealthcareWorkerRepository, HealthcareWorkerRepository>();
53 services.AddTransient<IHealthcareWorkerService, HealthcareWorkerService>();
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>();
69
70 services.AddTransient<IProcessJSONService, ProcessJSONService>();
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
96 app.UseCors(MyAllowSpecificOrigins);
97
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}
Note: See TracBrowser for help on using the repository browser.