source: Farmatiko/Startup.cs@ e42f61a

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

Add more services

  • Property mode set to 100644
File size: 3.7 KB
Line 
1using Microsoft.AspNetCore.Builder;
2using Microsoft.AspNetCore.Hosting;
3using Microsoft.AspNetCore.HttpsPolicy;
4using Microsoft.AspNetCore.SpaServices.AngularCli;
5using Microsoft.Extensions.Configuration;
6using Microsoft.Extensions.DependencyInjection;
7using Microsoft.Extensions.Hosting;
8using FarmatikoData;
9using Microsoft.EntityFrameworkCore;
10using FarmatikoServices;
11using FarmatikoData.FarmatikoRepoInterfaces;
12using FarmatikoData.FarmatikoRepo;
13using FarmatikoServices.FarmatikoServiceInterfaces;
14using FarmatikoServices.Services;
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 services.AddTransient<IHealthcareWorkerRepository, HealthcareWorkerRepository>();
53 services.AddTransient<IHealthcareWorkerService, HealthcareWorkerService>();
54 }
55
56 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
57 public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
58 {
59 if (env.IsDevelopment())
60 {
61 app.UseDeveloperExceptionPage();
62 }
63 else
64 {
65 app.UseExceptionHandler("/Error");
66 // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
67 app.UseHsts();
68 }
69
70 app.UseHttpsRedirection();
71 app.UseStaticFiles();
72 if (!env.IsDevelopment())
73 {
74 app.UseSpaStaticFiles();
75 }
76
77 app.UseRouting();
78
79 app.UseCors(MyAllowSpecificOrigins);
80
81 app.UseEndpoints(endpoints =>
82 {
83 endpoints.MapControllerRoute(
84 name: "default",
85 pattern: "{controller}/{action=Index}/{id?}");
86 });
87
88 app.UseSpa(spa =>
89 {
90 // To learn more about options for serving an Angular SPA from ASP.NET Core,
91 // see https://go.microsoft.com/fwlink/?linkid=864501
92
93 spa.Options.SourcePath = "ClientApp";
94
95 if (env.IsDevelopment())
96 {
97 spa.UseAngularCliServer(npmScript: "start");
98 }
99 });
100 }
101 }
102}
Note: See TracBrowser for help on using the repository browser.