source: Farmatiko/Startup.cs@ 4e72684

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

Add services

  • Property mode set to 100644
File size: 4.4 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
71 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
72 public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
73 {
74 if (env.IsDevelopment())
75 {
76 app.UseDeveloperExceptionPage();
77 }
78 else
79 {
80 app.UseExceptionHandler("/Error");
81 // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
82 app.UseHsts();
83 }
84
85 app.UseHttpsRedirection();
86 app.UseStaticFiles();
87 if (!env.IsDevelopment())
88 {
89 app.UseSpaStaticFiles();
90 }
91
92 app.UseRouting();
93
94 app.UseCors(MyAllowSpecificOrigins);
95
96 app.UseEndpoints(endpoints =>
97 {
98 endpoints.MapControllerRoute(
99 name: "default",
100 pattern: "{controller}/{action=Index}/{id?}");
101 });
102
103 app.UseSpa(spa =>
104 {
105 // To learn more about options for serving an Angular SPA from ASP.NET Core,
106 // see https://go.microsoft.com/fwlink/?linkid=864501
107
108 spa.Options.SourcePath = "ClientApp";
109
110 if (env.IsDevelopment())
111 {
112 spa.UseAngularCliServer(npmScript: "start");
113 }
114 });
115 }
116 }
117}
Note: See TracBrowser for help on using the repository browser.