Sun「無用」
Sun「無用」
Explore posts from servers
CC#
Created by Sun「無用」 on 9/4/2024 in #help
Get route information on controller
In my response model, I have stuff like method and path of the route. Is there any classes or methods I can call to inject that into the function? Example
class FooController : ControllerBase {
[HttpGet] // I know it's a get here, but not during runtime
async Task<ActionResult<CoolioResponse>> Bar(
// What to inject here? HttpContext?
) {

}
}
class FooController : ControllerBase {
[HttpGet] // I know it's a get here, but not during runtime
async Task<ActionResult<CoolioResponse>> Bar(
// What to inject here? HttpContext?
) {

}
}
50 replies
CC#
Created by Sun「無用」 on 9/3/2024 in #help
Class with same name as namespace
In the same app still (Ilanos), in my Ilanos.Application proj I have a lot of classes that are supposed to use the Joke class. However, for the sake of organization, I'm separating them like this:
|- Ilanos.Application
|- Mappers
|- Joke
|- Ilanos.Application
|- Mappers
|- Joke
The problem of that is the namespace name. The JokeResponseMapper, for example, would be at the namespace Ilanos.Application.Mappers.Joke while the Joke entity/model class is at Ilanos.Core.Entities. The compiler complains that the Ilanos.Application.Mappers.Joke namespace and the Joke class "have the same name", even if they're different, is there a way to keep the organization and have the named classes as they are?
24 replies
CC#
Created by Sun「無用」 on 9/3/2024 in #help
Unable to create DbContext
I'm trying to create by db tables right now, still in the start of a project. I have a ApplicationDbContext in my Infrastructure project and I'm running dotnet ef migrations Initial, that's all. Project is public for now, could be seen here (yes, I know it's messy, I don't like clean architecture, I mostly don't know how to do it, not my style of coding) Error Traceback:
Unable to create a 'DbContext' of type ''. The exception 'Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[Ilanos.Infrastructure.ApplicationDbContext]' while attempting to activate 'Ilanos.Infrastructure.ApplicationDbContext'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
Unable to create a 'DbContext' of type ''. The exception 'Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[Ilanos.Infrastructure.ApplicationDbContext]' while attempting to activate 'Ilanos.Infrastructure.ApplicationDbContext'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
48 replies
CC#
Created by Sun「無用」 on 5/30/2024 in #help
Testing practices and libraries
I'm just starting with testing, I'm not that much of a fan, most of the time for me it wasn't needed. But'll just try it just in case I actually need it in the future (probably never :d) What libraries should I use to make testing less bad? And what practices are recommeded when testing?
3 replies
CC#
Created by Sun「無用」 on 5/26/2024 in #help
Typed ids to plain id
My model is something like
// BaseEntity<UserId> has UserId Id
public class User : BaseEntity<UserId> {
public required string Name { get; init; ]
}
// BaseEntity<UserId> has UserId Id
public class User : BaseEntity<UserId> {
public required string Name { get; init; ]
}
How would I transform that UserId into a type that's valid in the database, like the Guid or int that's inside of the UserId?
36 replies
CC#
Created by Sun「無用」 on 5/25/2024 in #help
Transforming own type into ProblemDetails
So, I really like using application/problem+json to specify my results and for that I have my own ProblemResponse<T> type
public class ProblemResponse<T>
{
public required string Type { get; init; }
public required int Status { get; init; }
public required string Title { get; init; }
public required string Detail { get; init; }
public required string UriPath { get; init; }
public required string Method { get; init; }
public required T? Extensions { get; init; }
}
public class ProblemResponse<T>
{
public required string Type { get; init; }
public required int Status { get; init; }
public required string Title { get; init; }
public required string Detail { get; init; }
public required string UriPath { get; init; }
public required string Method { get; init; }
public required T? Extensions { get; init; }
}
Which has all the specification fields + extensions The thing is that dotnet's ProblemDetails type is not generic in any way, it uses a dictionary. The type could be shortened to this
public class ProblemDetails {
public string? Type { get; set; }
public string? Title { get; set; }
public int? Status { get; set; }
public string? Detail { get; set; }
public string? Instance { get; set; }
[JsonExtensionData]
public IDictionary<string, object?> Extensions { get; set; }
}
public class ProblemDetails {
public string? Type { get; set; }
public string? Title { get; set; }
public int? Status { get; set; }
public string? Detail { get; set; }
public string? Instance { get; set; }
[JsonExtensionData]
public IDictionary<string, object?> Extensions { get; set; }
}
Is there any ways to transform from my type to theirs? or do I just use my type and not use the application/problem+json header? sry for the long text
1 replies
CC#
Created by Sun「無用」 on 5/25/2024 in #help
Basic project structure for api/frontend
I've a small project I wanna build, but it'll need a frontend and a backend. I'd like to learn some Blazor, so I'll use that as Frontend and normal asp.net w/controllers for backend. I'm kinda stuck on project naming and organization though, do I use something like clean architecture, even if my project is way too small for that or do I just use like a *.Api, *.Blazor and *.Common? What should be the recommended there to keep it simple as much as possible?
51 replies
CC#
Created by Sun「無用」 on 6/21/2023 in #help
✅ ef not being able to update database migrations
I've been trying to learn aspnet and done just the basics of it. But when using dotnet ef database update, after adding a migration, the same SQLite Error 1: 'no such table: __EFMigrationsHistory'. happens, eventhough that table is being created (or was supposed to be created) on the initial migration. I only have 1 service and 1 model now, so that error makes no sense for me, as it's the only language that happened for me.
58 replies
CC#
Created by Sun「無用」 on 6/21/2023 in #help
How to get configurations variables?
I'm new to asp.net, been trying to create some apis. For now, I'm trying to get the db connection string, out of the appsettings.json. Is that possible or would I need to use something like .env variables with some extra configuration?
8 replies
CC#
Created by Sun「無用」 on 12/12/2022 in #help
❔ Errors when everything looks ok.
So, I'm dumb a aspnet api, with controllers, using sqlite. There are no syntax errors in the code, since it compiles, but when I try to do anything(any request), the same giant error appears. Error given on the file.
129 replies