-
Notifications
You must be signed in to change notification settings - Fork 0
/
Startup.cs
59 lines (51 loc) · 1.97 KB
/
Startup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using CatalogEditor.DatabaseContext;
using CatalogEditor.Deserializer;
using CatalogEditor.Fetcher;
using CatalogEditor.Initializer;
using CatalogEditor.Processor;
using CatalogEditor.Serializer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace CatalogEditor
{
public class Startup
{
private readonly IConfiguration _configuration;
private readonly IHostingEnvironment _hostingEnvironment;
public Startup(IConfiguration configuration, IHostingEnvironment hostingEnvironment)
{
_configuration = configuration;
_hostingEnvironment = hostingEnvironment;
}
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddContext(_configuration.GetValue<string>("DatabaseName"));
services
.AddTransient<IEntitySerializer, EntitySerializer>()
.AddTransient<IEntityDeserializer, EntityDeserializer>()
.AddTransient<ICategoryFetcher, CategoryFetcher>()
.AddTransient<ProductProcessor>()
.AddTransient<IImageFetcher>(
s => new ImageFetcher(
s.GetService<IContextFactory>(),
_configuration.GetValue<string>("UploadingPath"),
_configuration.GetValue<string>("DefaultImageRelativePath")
)
)
.AddTransient<IDatabaseInitializer, DatabaseInitializer>();
}
public void Configure(IApplicationBuilder app, IDatabaseInitializer initializer)
{
app.UseStaticFiles();
if (_hostingEnvironment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
initializer.Seed().Wait();
}
}
}