-
Notifications
You must be signed in to change notification settings - Fork 0
/
Startup.cs
126 lines (109 loc) · 4.32 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using SearchEngine.Contexts;
using SearchEngine.Api.Core.Services;
using SearchEngine.CronJobs;
using SearchEngine.Api.Core.Interfaces;
using Quartz;
using Quartz.Impl;
using Quartz.Spi;
using search.SearchEngine.Api.Core.Cronjobs;
using MongoDB.Driver;
using SearchEngine.Api.Core.Files;
namespace SearchEngine
{
/// <summary>
/// Configures services and the app's request pipeline.
/// </summary>
public class Startup
{
/// <summary>
/// Initializes a new instance of the <see cref="Startup"/> class.
/// </summary>
/// <param name="configuration">The configuration for the application.</param>
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
/// <summary>
/// Configures the services used by the application.
/// </summary>
/// <param name="services">The collection of services to add to the container.</param>
public void ConfigureServices(IServiceCollection services)
{
// Configure MongoDB settings
services.Configure<MongoDBSettings>(Configuration.GetSection("MongoDBSettings"));
// Add MongoDBContext
services.AddSingleton<MongoDBContext>();
services.AddSingleton<CloudStoreManager>();
services.AddSingleton<FileManager>();
services.AddSingleton<DocumentService>();
services.AddSingleton<IMongoClient, MongoClient>(sp =>
{
// var connectionString = Configuration.GetConnectionString("MongoDBSettings:ConnectionString");
return new MongoClient("mongodb://localhost:27017/NebularFinder");
// var mongoDBSettings = sp.GetRequiredService<MongoDBSettings>();
// return new MongoClient(mongoDBSettings.ConnectionString);
});
services.AddScoped(sp =>
{
var client = sp.GetRequiredService<IMongoClient>();
return client.GetDatabase("search");
});
// Add Document Service
services.AddSingleton<IDocumentService, DocumentService>();
// Add CORS policy
services.AddCors(options =>
{
options.AddDefaultPolicy(builder =>
{
builder.WithOrigins("http://localhost:3000")
.AllowAnyMethod()
.AllowAnyHeader();
});
});
// Add Quartz.NET services
// Add Quartz.NET services
services.AddSingleton<IJobFactory, JobFactory>(); // Ensure you have a JobFactory implementation
services.AddSingleton<ISchedulerFactory, StdSchedulerFactory>();
services.AddSingleton<DocumentIndexingJob>();
services.AddSingleton(new JobSchedule(
jobType: typeof(DocumentIndexingJob),
cronExpression: "0/5 * * * * ?"));
services.AddHostedService<CronService>();
services.Configure<FormOptions>(options =>
{
options.MultipartBodyLengthLimit = 52428800;
});
services.AddScoped<IDocumentService, DocumentService>();
// Add MVC controllers
services.AddControllers();
}
/// <summary>
/// Configures the application's request pipeline.
/// </summary>
/// <param name="app">The application builder used to configure the HTTP request pipeline.</param>
/// <param name="env">The web hosting environment.</param>
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseStaticFiles();
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseCors();
app.UseStaticFiles();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}