Creating and using an incremental source generator
I wanna create an incremental source generator for my web API project, but I cannot for the life of me understand how to create a source generator at all. I'm even having a hard time understanding the documentation that does exist. Is there anyone that's able to help?
I have a pretty clear idea of what I wanna do: I have a collection of HTTP endpoints in one class, which get turned into controllers, commands, and DTOs.
UserEndpoints.g.cs
30 Replies
what are you actually trying to achieve with
GenerateHttpEndpoints
generate controllers, commands, command handlers, dtos
From what
what do you mean from what? it's all laid out in the post
You already have a controller there
You can’t just generate something from nothing
How would it know what the DTO is supposed to even be?
Based on what?
from the method arguments...?
So who’s using the DTO then?
like
You’re going to need the DTO in the first place to post to an endpoint if you’re not getting these from query parameters
the
Endpoints.User
class is basically nothing. it's not used anywhere. it's not a controller. it only exists to generate the actual controllerWhat you’ve posted looks like a controller
and i'm saying it isn't one
So you’re going to write a class that looks like a controller, is supposed to be a controller but isn’t because you want to… source generate it
it's supposed to look like one so people reading the source have an idea of what's going on
but i simply cannot be bothered writing full controllers and services and commands and command handlers and dtos for every single thing i implement
But what you have is 90% a controller….
I don’t get it
If you don’t want to write any code, write a swagger doc and generate all controllers and types
look if you don't wanna help, you don't have to
that's fine
i don't think you're understanding what you want to do is backward
this is 99% a controller which you say you don't want to write
it's not anything. you can't post to an endpoint like that, can you? it doesn't take a DTO after all
right... so just change it to take a DTO and then inherit
ControllerBase
and put [ApiController]
on the class
99%and then i need a command. and a command handler. and maybe a service if i feel like it
like there's so much more that needs to be generated
i don't know what you're talking about
i dont know what a command or command handler is
i assume you mean mediatr
or something
that's a completely different topic and no you don't need that
i decided i want it
people building APIs only to have controllers => mediatr => handler => service end up building a lot of bloat
your desire to generate code comes from over engineering a solution
this is meant to be a completely feature rich, public api, everything open source, with potentially thousands of daily users
ok
where does mediatr come into play
you really make people wanna ask questions in this server you know
"potentially thousands of daily users"
you haven't got 1 yet
controller => service
what's wrong with that?