cumslvt13
cumslvt13
CC#
Created by cumslvt13 on 4/25/2024 in #help
Dealing with sub-models in request endpoint response pattern
I'm using RERP (request endpoint response) pattern to structure my api endpoints. Recently I've noticed that some requests have lots of fields that could be combined into a separate sub-model as example:
public record CreateCustomerRequest
{
// main group of fields that are used t create customer
public required string Name { get; init; }
public required string Identifier { get; init; }
public required bool Active { get; init; }

// logically grouped fields, that are used to create other entity
public required string CompanyName { get; init; }
public required string CompanyEmail { get; init; }
public required string CompanyIndustry { get; init; }
// ... and so on
}
public record CreateCustomerRequest
{
// main group of fields that are used t create customer
public required string Name { get; init; }
public required string Identifier { get; init; }
public required bool Active { get; init; }

// logically grouped fields, that are used to create other entity
public required string CompanyName { get; init; }
public required string CompanyEmail { get; init; }
public required string CompanyIndustry { get; init; }
// ... and so on
}
It seems obvious that those fields could be mapped to separate model, but question is: where should I put it? Currently my folder structure is following:
Endpoints/
EnitityName/
Requests/
Responses/
EndpointExtensions.cs
Endpoints/
EnitityName/
Requests/
Responses/
EndpointExtensions.cs
I don't really like idea of creating a single folder named Common or Shared and dumping all of the similar models there nor I like the idea of keeping that model with requests, because name would be too generic like CompanyInfoModel which doesn't actually say anything about relation to the CreateCustomerRequest when viewed in swagger. What are your approaches/advises in such situations. How you deal with that kind of stuff?
1 replies
CC#
Created by cumslvt13 on 3/26/2024 in #help
Background upload of an IFormFile to Azure blob storage
I have a few endpoints that are dealing with files in my app. Some of them may accept IFormFileCollection or regular IFormFile. During the request hanlding content of those files is being uploaded to azure blob storage. The problem I encountered is that process of uploading to the blob storage can take 3-5 seconds. Are there any options to upload files in the background and return after persisting data to the db? As far as I understand it would be a bad practice to reference/use IFormFile after returning response the the client, so just creating a background job and passing it as a reference would not be an option
18 replies
CC#
Created by cumslvt13 on 11/7/2023 in #help
✅ What's the point of ModelSnapshot in ef core migrations
I'm trying to move my migrations to a separate projects in case I want to change a db provider. I've moved my existing migrations to the separate project and that's what I've got now:
Application.Core <-- ApplicationDbContext
Application.Migrations.MsSql <-- References Application.Persistence, contains migrations
Application.Core <-- ApplicationDbContext
Application.Migrations.MsSql <-- References Application.Persistence, contains migrations
In my Application.Core project I've added the following config for DI:
services.AddDbContext(o => o.UseSqlServer("connectionString"));
services.AddDbContext(o => o.UseSqlServer("connectionString"));
I didn't add x => x.MigrationsAssembly("WebApplication1.Migrations") call as it shown in the docs (https://learn.microsoft.com/en-us/ef/core/managing-schemas/migrations/projects) My questions is: how come EF still works even though it doesn't reference Migrations project where AppContextModelSnapshot is stored? And what are potential issues with my approach?
37 replies
CC#
Created by cumslvt13 on 10/5/2023 in #help
❔ Loading/Using blazor in a webworker
We're using blazor wasm in a web project with a SPA combination. Blazor is used purely for business and computation logic (no components at all), while Angular is used to render UI and for user interactions. Since blazor is kind of slow and clumsy, I'd like to try to improve its performance. Questions are following: 1) Is there a ready solution/example on how to load blazor files in the webworker to offload the work from the main UI thread? 2) Is it possible to keep blazor running in a webworker and call dotnet methods from main UI?
3 replies
CC#
Created by cumslvt13 on 5/11/2023 in #help
✅ Binding array with default value doesn't work
I've got the following model and controller
public class MyModel
{
public int? Test { get; set; } = 10;
public IEnumerable<string> Sections { get; set; } = Array.Empty<string>();
}

[ApiController]
[Route("[controller]")]
public class TestController : ControllerBase
{
[HttpGet]
public ActionResult<MyModel> Test([FromQuery] MyModel model)
{
return Ok(model);
}
}
public class MyModel
{
public int? Test { get; set; } = 10;
public IEnumerable<string> Sections { get; set; } = Array.Empty<string>();
}

[ApiController]
[Route("[controller]")]
public class TestController : ControllerBase
{
[HttpGet]
public ActionResult<MyModel> Test([FromQuery] MyModel model)
{
return Ok(model);
}
}
The https://localhost:5001/test?Test=3&Sections=USER resolves to {"test":3,"sections":[]}, but if I remove default value for a Sections property it resolves to {"test":3,"sections":["USER"]}. Why behavior is different from int default value?
52 replies
CC#
Created by cumslvt13 on 12/11/2022 in #help
❔ Decent reference ASP.NET project
I am looking for a reference project for investigation purposes. Appreciate if anyone can share repo link of a somewhat complex ASP.NET project. I've seen some repos with example of Clean Architecture on github, but they seem to be a bit poor without any business logic. Something like dotnet-podcasts or eShopOnContainers would do great.
2 replies
CC#
Created by cumslvt13 on 10/24/2022 in #help
dotnet publish solution excluding projects with tests
Is it possible to publish solution and exclude projects with tests? I have the following project structure and docker image doesn't actually need those *.Tests projects to be published:
└───src
├───DemoApp.Publisher
├───DemoApp.Publisher.Tests
├───DemoApp.Shared
├───DemoApp.Worker
└───DemoApp.Worker.Tests
└───src
├───DemoApp.Publisher
├───DemoApp.Publisher.Tests
├───DemoApp.Shared
├───DemoApp.Worker
└───DemoApp.Worker.Tests
Also, is it a good idea to build single docker image instead of two separate ones? DemoApp.Publisher and DemoApp.Worker are meant to be standalone apps.
3 replies