Skip to content

Commit 57013b0

Browse files
committed
Upgrade to dotnet-10
1 parent e3fde67 commit 57013b0

7 files changed

Lines changed: 209 additions & 209 deletions

File tree

Contracts/Contracts.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>

FilesAPI/FilesAPI.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
66
</PropertyGroup>
77

88
<ItemGroup>
99
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
10-
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.3" />
10+
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.0" />
1111
</ItemGroup>
1212

1313
<ItemGroup>

FilesAPI/Startup.cs

Lines changed: 129 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using Contracts;
32
using Microsoft.AspNetCore.Builder;
43
using Microsoft.AspNetCore.Diagnostics;
@@ -9,7 +8,7 @@
98
using Microsoft.Extensions.Configuration;
109
using Microsoft.Extensions.DependencyInjection;
1110
using Microsoft.Extensions.Hosting;
12-
using Microsoft.OpenApi.Models;
11+
using Microsoft.OpenApi;
1312
using Models.Events;
1413
using Models.Exceptions;
1514
using Models.Settings;
@@ -18,145 +17,146 @@
1817
using Services.Events;
1918
using Services.Events.Handlers;
2019
using Services.Repositories;
20+
using System;
2121

2222
namespace FilesAPI
2323
{
24-
public class Startup
25-
{
26-
public Startup(IConfiguration configuration)
27-
{
28-
Configuration = configuration;
29-
}
24+
public class Startup
25+
{
26+
public Startup(IConfiguration configuration)
27+
{
28+
Configuration = configuration;
29+
}
30+
31+
public IConfiguration Configuration { get; }
32+
33+
// This method gets called by the runtime. Use this method to add services to the container.
34+
public void ConfigureServices(IServiceCollection services)
35+
{
36+
// Configure Kestrel server options for unlimited file uploads
37+
services.Configure<KestrelServerOptions>(options =>
38+
{
39+
options.Limits.MaxRequestBodySize = null; // Remove limit completely
40+
options.Limits.MinRequestBodyDataRate = null; // Remove timeout for slow uploads
41+
options.Limits.MinResponseDataRate = null; // Remove timeout for slow downloads
42+
options.Limits.MaxConcurrentConnections = null; // Remove connection limit
43+
options.Limits.MaxConcurrentUpgradedConnections = null; // Remove upgraded connection limit
44+
});
45+
46+
// Note: IIS file size limits are configured via web.config See web.config for
47+
// maxAllowedContentLength and requestLimits configuration Configure form options for
48+
// unlimited file uploads
49+
services.Configure<FormOptions>(options =>
50+
{
51+
options.ValueLengthLimit = int.MaxValue; // Remove form value length limit
52+
options.MultipartBodyLengthLimit = long.MaxValue; // Remove multipart body limit
53+
options.MultipartHeadersLengthLimit = int.MaxValue; // Remove header length limit
54+
options.MultipartBoundaryLengthLimit = int.MaxValue; // Remove boundary length limit
55+
options.KeyLengthLimit = int.MaxValue; // Remove key length limit
56+
options.ValueCountLimit = int.MaxValue; // Remove value count limit
57+
options.BufferBody = true; // Buffer the request body
58+
options.MemoryBufferThreshold = int.MaxValue; // Set memory buffer threshold
59+
});
60+
services.AddCors(options =>
61+
{
62+
options.AddPolicy("AllowAll",
63+
builder =>
64+
{
65+
builder
66+
.AllowAnyOrigin()
67+
.AllowAnyMethod()
68+
.AllowAnyHeader();
69+
});
70+
});
71+
services.AddSwaggerGen(c =>
72+
{
73+
c.SwaggerDoc("v1", new OpenApiInfo
74+
{
75+
Title = "Files API",
76+
Version = "v1"
77+
});
78+
});
79+
//App Settings Injection
80+
services.Configure<MongoDBAppSettings>(Configuration.GetSection("MongoDBAppSettings"));
81+
services.Configure<LiteDBAppSettings>(Configuration.GetSection("LiteDBAppSettings"));
3082

31-
public IConfiguration Configuration { get; }
83+
// Configure database services based on environment
84+
var useEmbeddedDatabase = Configuration.GetValue<bool>("USE_EMBEDDED_DATABASE", false) ||
85+
Environment.GetEnvironmentVariable("USE_EMBEDDED_DATABASE") == "true";
3286

33-
// This method gets called by the runtime. Use this method to add services to the container.
34-
public void ConfigureServices(IServiceCollection services)
35-
{
36-
// Configure Kestrel server options for unlimited file uploads
37-
services.Configure<KestrelServerOptions>(options =>
38-
{
39-
options.Limits.MaxRequestBodySize = null; // Remove limit completely
40-
options.Limits.MinRequestBodyDataRate = null; // Remove timeout for slow uploads
41-
options.Limits.MinResponseDataRate = null; // Remove timeout for slow downloads
42-
options.Limits.MaxConcurrentConnections = null; // Remove connection limit
43-
options.Limits.MaxConcurrentUpgradedConnections = null; // Remove upgraded connection limit
44-
});
45-
46-
// Note: IIS file size limits are configured via web.config
47-
// See web.config for maxAllowedContentLength and requestLimits configuration
48-
// Configure form options for unlimited file uploads
49-
services.Configure<FormOptions>(options =>
50-
{
51-
options.ValueLengthLimit = int.MaxValue; // Remove form value length limit
52-
options.MultipartBodyLengthLimit = long.MaxValue; // Remove multipart body limit
53-
options.MultipartHeadersLengthLimit = int.MaxValue; // Remove header length limit
54-
options.MultipartBoundaryLengthLimit = int.MaxValue; // Remove boundary length limit
55-
options.KeyLengthLimit = int.MaxValue; // Remove key length limit
56-
options.ValueCountLimit = int.MaxValue; // Remove value count limit
57-
options.BufferBody = true; // Buffer the request body
58-
options.MemoryBufferThreshold = int.MaxValue; // Set memory buffer threshold
59-
});
60-
services.AddCors(options =>
61-
{
62-
options.AddPolicy("AllowAll",
63-
builder =>
64-
{
65-
builder
66-
.AllowAnyOrigin()
67-
.AllowAnyMethod()
68-
.AllowAnyHeader();
69-
});
70-
});
71-
services.AddSwaggerGen(c =>
72-
{
73-
c.SwaggerDoc("v1", new OpenApiInfo
74-
{
75-
Title = "Files API",
76-
Version = "v1"
77-
});
78-
});
79-
//App Settings Injection
80-
services.Configure<MongoDBAppSettings>(Configuration.GetSection("MongoDBAppSettings"));
81-
services.Configure<LiteDBAppSettings>(Configuration.GetSection("LiteDBAppSettings"));
87+
if (useEmbeddedDatabase)
88+
{
89+
// Use LiteDB for self-contained operation
90+
var databasePath = Environment.GetEnvironmentVariable("DATABASE_PATH") ??
91+
Configuration.GetValue<string>("DATABASE_PATH", "./data/filesapi.db");
92+
var uploadsPath = Environment.GetEnvironmentVariable("UPLOADS_PATH") ??
93+
Configuration.GetValue<string>("UPLOADS_PATH", "./uploads");
8294

83-
// Configure database services based on environment
84-
var useEmbeddedDatabase = Configuration.GetValue<bool>("USE_EMBEDDED_DATABASE", false) ||
85-
Environment.GetEnvironmentVariable("USE_EMBEDDED_DATABASE") == "true";
86-
87-
if (useEmbeddedDatabase)
88-
{
89-
// Use LiteDB for self-contained operation
90-
var databasePath = Environment.GetEnvironmentVariable("DATABASE_PATH") ??
91-
Configuration.GetValue<string>("DATABASE_PATH", "./data/filesapi.db");
92-
var uploadsPath = Environment.GetEnvironmentVariable("UPLOADS_PATH") ??
93-
Configuration.GetValue<string>("UPLOADS_PATH", "./uploads");
94-
95-
services.AddScoped<IStorageRepository>(provider =>
96-
new Services.Repositories.LiteDbStorageRepository(databasePath, uploadsPath));
97-
services.AddScoped<IFileDetailsRepository>(provider =>
98-
new Services.Repositories.LiteDbFileDetailsRepository(databasePath));
99-
services.AddScoped<IDownloadAnalyticsRepository>(provider =>
100-
new Services.Repositories.LiteDbDownloadAnalyticsRepository(databasePath));
101-
}
102-
else
103-
{
104-
// Use MongoDB for traditional operation
105-
services.AddScoped<IStorageRepository, StorageRepository>();
106-
services.AddScoped<IFileDetailsRepository, FileDetailsRepository>();
107-
services.AddScoped<IDownloadAnalyticsRepository, Services.Repositories.MongoDbDownloadAnalyticsRepository>();
108-
}
95+
services.AddScoped<IStorageRepository>(provider =>
96+
new Services.Repositories.LiteDbStorageRepository(databasePath, uploadsPath));
97+
services.AddScoped<IFileDetailsRepository>(provider =>
98+
new Services.Repositories.LiteDbFileDetailsRepository(databasePath));
99+
services.AddScoped<IDownloadAnalyticsRepository>(provider =>
100+
new Services.Repositories.LiteDbDownloadAnalyticsRepository(databasePath));
101+
}
102+
else
103+
{
104+
// Use MongoDB for traditional operation
105+
services.AddScoped<IStorageRepository, StorageRepository>();
106+
services.AddScoped<IFileDetailsRepository, FileDetailsRepository>();
107+
services.AddScoped<IDownloadAnalyticsRepository, Services.Repositories.MongoDbDownloadAnalyticsRepository>();
108+
}
109109

110-
//services.AddSingleton<IStorageService, FilesService>();
111-
services.AddScoped<IStorageService, StorageService>();
112-
services.AddScoped<IAnalyticsService, AnalyticsService>();
113-
services.AddSingleton<ISettingsService, SettingsService>();
110+
//services.AddSingleton<IStorageService, FilesService>();
111+
services.AddScoped<IStorageService, StorageService>();
112+
services.AddScoped<IAnalyticsService, AnalyticsService>();
113+
services.AddSingleton<ISettingsService, SettingsService>();
114114

115-
services.AddScoped<RecordDownloadHandler>();
116-
services.AddScoped<EventHandlerContainer>();
117-
EventHandlerContainer.Subscribe<FileDownloadedEvent, RecordDownloadHandler>();
115+
services.AddScoped<RecordDownloadHandler>();
116+
services.AddScoped<EventHandlerContainer>();
117+
EventHandlerContainer.Subscribe<FileDownloadedEvent, RecordDownloadHandler>();
118118

119-
services.AddControllers();
120-
}
119+
services.AddControllers();
120+
}
121121

122-
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
123-
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
124-
{
125-
app.UseCors("AllowAll");
126-
app.UseStaticFiles();
127-
var swaggerUrl = "/swagger/v1/swagger.json";
128-
if (env.IsDevelopment())
129-
{
130-
app.UseDeveloperExceptionPage();
131-
}
122+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
123+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
124+
{
125+
app.UseCors("AllowAll");
126+
app.UseStaticFiles();
127+
var swaggerUrl = "/swagger/v1/swagger.json";
128+
if (env.IsDevelopment())
129+
{
130+
app.UseDeveloperExceptionPage();
131+
}
132132

133-
app.UseSwagger();
134-
app.UseSwaggerUI(c =>
135-
{
136-
c.SwaggerEndpoint(swaggerUrl, "Files API V1");
137-
c.RoutePrefix = string.Empty;
138-
});
133+
app.UseSwagger();
134+
app.UseSwaggerUI(c =>
135+
{
136+
c.SwaggerEndpoint(swaggerUrl, "Files API V1");
137+
c.RoutePrefix = string.Empty;
138+
});
139139

140-
app.UseHttpsRedirection();
141-
app.UseRouting();
140+
app.UseHttpsRedirection();
141+
app.UseRouting();
142142

143-
app.UseExceptionHandler(a => a.Run(async context =>
144-
{
145-
var exceptionHandlerPathFeature = context.Features.Get<IExceptionHandlerPathFeature>();
146-
var exception = exceptionHandlerPathFeature.Error;
147-
if (exception is FilesApiException)
148-
{
149-
var result = JsonConvert.SerializeObject(new { error = exception.Message });
150-
context.Response.ContentType = "application/json";
151-
context.Response.StatusCode = StatusCodes.Status400BadRequest;
152-
await context.Response.WriteAsync(result);
153-
}
154-
}));
143+
app.UseExceptionHandler(a => a.Run(async context =>
144+
{
145+
var exceptionHandlerPathFeature = context.Features.Get<IExceptionHandlerPathFeature>();
146+
var exception = exceptionHandlerPathFeature.Error;
147+
if (exception is FilesApiException)
148+
{
149+
var result = JsonConvert.SerializeObject(new { error = exception.Message });
150+
context.Response.ContentType = "application/json";
151+
context.Response.StatusCode = StatusCodes.Status400BadRequest;
152+
await context.Response.WriteAsync(result);
153+
}
154+
}));
155155

156-
app.UseEndpoints(endpoints =>
157-
{
158-
endpoints.MapControllers();
159-
});
160-
}
161-
}
156+
app.UseEndpoints(endpoints =>
157+
{
158+
endpoints.MapControllers();
159+
});
160+
}
161+
}
162162
}

Models/Models.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>

Services.Tests/Services.Tests.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55

66
<IsPackable>false</IsPackable>
77
</PropertyGroup>
88

99
<ItemGroup>
1010
<PackageReference Include="NSubstitute" Version="5.3.0" />
11-
<PackageReference Include="NUnit" Version="4.3.2" />
12-
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0" />
13-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
11+
<PackageReference Include="NUnit" Version="4.4.0" />
12+
<PackageReference Include="NUnit3TestAdapter" Version="6.0.1" />
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
1414
</ItemGroup>
1515

1616
<ItemGroup>

0 commit comments

Comments
 (0)