michalgrzyska
michalgrzyska
CC#
Created by michalgrzyska on 10/8/2024 in #help
Looking for AI dev to back me up a little in open source project
what model does it use exactly? I cannot see
7 replies
CC#
Created by Hambones on 4/24/2024 in #help
Internal classes
I said " especially if you use a lot of DI there", but yes fair enough, there was no mentioning DI from the author. I wanted to point it out as a probably good idea of designing an app (unless its not some game for example)
16 replies
CC#
Created by Hambones on 4/24/2024 in #help
Internal classes
yes - when you explicitly register stuff in DI container, this is perfectly valid case to use interfaces with an implementation
16 replies
CC#
Created by Hambones on 4/24/2024 in #help
Internal classes
this is generally what interfaces are for 😄 you make a public interface and the implementation is internal. you will notice one big convenience - you can inject whatever you want into implementation's contructor and all dependencies would still be internal, because interface does not expose a constructor. (of course this is only one of many purposes of interfaces)
16 replies
CC#
Created by cow on 4/22/2024 in #help
✅ How to Deserialize dd-MM-yyyy in System.Text.Json?
this is my example (we dont know how the solutions looks), there is a possibility that new Date() is not enough, however I think we can both agree that this is a frontend responsibility to adjust to API standard rather than adjusting API for frontend code here
41 replies
CC#
Created by Hambones on 4/24/2024 in #help
Internal classes
personally I think this may be a good case to use interfaces, especially if you use a lot of DI there
16 replies
CC#
Created by cow on 4/22/2024 in #help
✅ How to Deserialize dd-MM-yyyy in System.Text.Json?
if this is an angular app, you probably are taking it from input with FormControl, can't you just map is there with new Date(control.value).toISOString() before sending to api? I know, it's an Angular response in C# chat, but still a possible solution to a problem
41 replies
CC#
Created by michalgrzyska on 12/11/2023 in #help
Testcontainers in integration tests vs BackgroundService
code:
public class TestApplicationFactory : WebApplicationFactory<Program>, IAsyncLifetime
{
private DbConnection _dbConnection = null!;
private Respawner _respawner = null!;

private readonly PostgreSqlContainer _dbContainer = new PostgreSqlBuilder()
.WithDatabase("db")
.WithUsername("user")
.WithPassword("password")
.Build();

protected override void ConfigureWebHost(IWebHostBuilder builder)
{
builder.ConfigureTestServices(services =>
{
services.RemoveAll<DbContextOptions<MyContext>>();
services.RemoveAll<MyContext>();

services.AddDbContext<MyContext>(x => x.UseNpgsql(_dbContainer.GetConnectionString()));
});
}

public async Task InitializeAsync()
{
await _dbContainer.StartAsync();

_dbConnection = new NpgsqlConnection(_dbContainer.GetConnectionString());
await _dbConnection.OpenAsync();

using var scope = Services.CreateScope();
var dbContext = scope.ServiceProvider.GetRequiredService<MyContext>();
await dbContext.Database.MigrateAsync();

_respawner = await Respawner.CreateAsync(_dbConnection, new RespawnerOptions
{
DbAdapter = DbAdapter.Postgres,
SchemasToInclude = ["public"]
});
}

public async Task ResetDatabaseAsync() => await _respawner.ResetAsync(_dbConnection);
public new async Task DisposeAsync() => await _dbContainer.StopAsync();
}
public class TestApplicationFactory : WebApplicationFactory<Program>, IAsyncLifetime
{
private DbConnection _dbConnection = null!;
private Respawner _respawner = null!;

private readonly PostgreSqlContainer _dbContainer = new PostgreSqlBuilder()
.WithDatabase("db")
.WithUsername("user")
.WithPassword("password")
.Build();

protected override void ConfigureWebHost(IWebHostBuilder builder)
{
builder.ConfigureTestServices(services =>
{
services.RemoveAll<DbContextOptions<MyContext>>();
services.RemoveAll<MyContext>();

services.AddDbContext<MyContext>(x => x.UseNpgsql(_dbContainer.GetConnectionString()));
});
}

public async Task InitializeAsync()
{
await _dbContainer.StartAsync();

_dbConnection = new NpgsqlConnection(_dbContainer.GetConnectionString());
await _dbConnection.OpenAsync();

using var scope = Services.CreateScope();
var dbContext = scope.ServiceProvider.GetRequiredService<MyContext>();
await dbContext.Database.MigrateAsync();

_respawner = await Respawner.CreateAsync(_dbConnection, new RespawnerOptions
{
DbAdapter = DbAdapter.Postgres,
SchemasToInclude = ["public"]
});
}

public async Task ResetDatabaseAsync() => await _respawner.ResetAsync(_dbConnection);
public new async Task DisposeAsync() => await _dbContainer.StopAsync();
}
2 replies