Core
Core
CC#
Created by Core on 6/3/2024 in #help
How to block the execution of a method when running EF migration
It was located in the main project, not in which the dbcontext. But either way, it should work from the main project, because for EF commands both the source project and the other project where the dbcontext is located should be specified
24 replies
CC#
Created by Core on 6/3/2024 in #help
How to block the execution of a method when running EF migration
It was, I did a Console.Write in the factory
24 replies
CC#
Created by Core on 6/3/2024 in #help
How to block the execution of a method when running EF migration
I found a solution which is available from .NET 7. EF exposes a static flag trough EF.IsDesignTime. I simply organized the Program.cs content in a way to only have code needed for EF in design time.
24 replies
CC#
Created by Core on 6/3/2024 in #help
How to block the execution of a method when running EF migration
Yes, and that is what I implemented. My output shows that the DesignTimeFactory was executed and not the regular DbContext
24 replies
CC#
Created by Core on 6/3/2024 in #help
How to block the execution of a method when running EF migration
Sorry, it turns out that IDesignTimeDbContextFactory is no longer supported in .NET 6 and above. I found a discussion on GitHub about it
24 replies
CC#
Created by Core on 6/3/2024 in #help
How to block the execution of a method when running EF migration
No description
24 replies
CC#
Created by Core on 6/3/2024 in #help
How to block the execution of a method when running EF migration
Sorry, my notifications were turned off. Thank you, I will look into this as soon as I can
24 replies
CC#
Created by Core on 6/3/2024 in #help
How to block the execution of a method when running EF migration
No description
24 replies
CC#
Created by Core on 6/3/2024 in #help
How to block the execution of a method when running EF migration
For the app that external service call is essential, but it also gets executed whenever I create a migration. I think that is because the app is built one time before the EF command
24 replies
CC#
Created by Core on 6/3/2024 in #help
How to block the execution of a method when running EF migration
The background service is an IHostedLifecycleService. I also create an instance of that just to do a http call, but all of this happens once. When I run the EF command dotnet ef migrations add ... it also executes the HTTP call. The app is not running when the migration is being created
c#
services.AddHttpClient<ICoordinationService, CoordinationService>((serviceProvider, httpClient) =>
{
var options = serviceProvider.GetRequiredService<IOptions<CoordinationServiceOption>>().Value;

httpClient.BaseAddress = new Uri(options.BaseUrl);
})
.ConfigurePrimaryHttpMessageHandler(() =>
new SocketsHttpHandler { PooledConnectionLifetime = TimeSpan.FromMinutes(2) });

var coordinationService = services.BuildServiceProvider().GetRequiredService<ICoordinationService>();
var instanceConfig = coordinationService.GetInstanceConfig().Result;
c#
services.AddHttpClient<ICoordinationService, CoordinationService>((serviceProvider, httpClient) =>
{
var options = serviceProvider.GetRequiredService<IOptions<CoordinationServiceOption>>().Value;

httpClient.BaseAddress = new Uri(options.BaseUrl);
})
.ConfigurePrimaryHttpMessageHandler(() =>
new SocketsHttpHandler { PooledConnectionLifetime = TimeSpan.FromMinutes(2) });

var coordinationService = services.BuildServiceProvider().GetRequiredService<ICoordinationService>();
var instanceConfig = coordinationService.GetInstanceConfig().Result;
24 replies
CC#
Created by Indeed on 6/3/2024 in #help
String enums - current consensus
If you need something similar to enum just with strings then you could do the following:
c#
public static class SortOrder
{
public const string Ascending = "asc";

public const string Descending = "desc";
}
c#
public static class SortOrder
{
public const string Ascending = "asc";

public const string Descending = "desc";
}
28 replies
CC#
Created by Core on 5/22/2024 in #help
Isolation level for reading a row only once
Thanks, then I will go with a distributed lock
4 replies
CC#
Created by Core on 5/16/2024 in #help
How to structure interfaces and their implementations
How should I name the folder in which I group the interface and implementation? For example: UserRepository and IUserRepository, how should I name the parent folder?
7 replies
CC#
Created by Core on 5/16/2024 in #help
How to structure interfaces and their implementations
Thank you, I will migrate to the 2 :)) I had a feeling my choice was not the best
7 replies
CC#
Created by Core on 5/16/2024 in #help
✅ How to create a folder in project root?
Great! Thanks
9 replies
CC#
Created by Core on 5/16/2024 in #help
✅ How to create a folder in project root?
Thank you, I will try that
9 replies
CC#
Created by Core on 5/15/2024 in #help
Microservices - confusion about the structure
I got it, thank you
4 replies
CC#
Created by Array on 5/15/2024 in #help
Recursion, help finding the base case?
The else statement is redundant, because if n != 0 it will simply execute the code after the if (n == 0) statement
95 replies
CC#
Created by Core on 5/13/2024 in #help
UUID v4 vs v7
In my case nothing, since I am not working in distributed environment. It is just a hobby project, but I like to try out new concepts
8 replies
CC#
Created by Core on 5/13/2024 in #help
UUID v4 vs v7
I switched because the performance of the UUID 7 in Postgres is the same as an incremented value. A detailed benchmark can be seen here: https://ardentperf.com/2024/02/03/uuid-benchmark-war/ The only downside is that it takes up a lot of space
8 replies