Learning Developer needs .NET Architecture advice
Hello all,
I've been learning for a year and got the hang of making basic apps with .NET. I've had experience with a normal layered 'coupled' architecture with EF CORE, viewmodels and Razor pages.
Now I have to build a website with accounts, files uploading etc some other features that i will work on for 6 months. But I will work on it solo and i want it to be scalable after, and clean code.
I've been looking at enterprise Architectural patterns but a lot of them seem in my case overkill/over my head. Does anyone have ideas how to make a very solid app with my profile?
25 Replies
As long as you avoid spaghetti code (everything hard-coupling everything else), you'll likely be fine. I'd suggest taking a look at VSA (vertical slice architecture) as a way to organize your code, as I personally really like it and find it matches most projects well.
There will be cross-cutting concerns, and thats fine.
I was currently also looking at vertical slice, glad you suggest the same. Would it make sense to use mediatr for CQRS and then in lets say a Handler for a crud operation inject the DB directly?
Mediator (or in fact any other similar thing) doesn't really make sense at all if its just a web api, imho
where it starts paying off is when you have other applications (a cli? an admin tool?) that needs to be able to run the same types of "commands" as you would in the webapp
I would however suggest taking a look at Viceroys wonderful Immediate platform: $ip
ImmediatePlatform
ImmediatePlatform
Libraries for building modern, maintainable .NET applications leveraging the Vertical Slice Architecture and Mediator pattern with no boilerplate. Extensible. Fast. Source Generated. Open Source.
its made by one of the associates of this discord who has a frankly insane amount of experience. might be a bit too advanced, depends on where you are at in your learning
interesting thank you, like i said most of this is a first for me so need to figure some stuff out. Sorry for the dumb question but then lets say i dont use mediator, does it then make sense to lets say have a feature (Schedule for example) have a Razor page cshtml under it and then just a interface for the create and a service for the create which injects the Db directly?
will def take a look if its too advanced can still be useful tyvm!
I don't fully follow the example.
Like if we're talking about concretely implementing a vertical slice
And I'm not very familiar with ASP.NET frontend stuff like razor, I'm strictly a backend developer 🙂
How would a simplified folder look like
disregarding front end
razor IS frontend
like database communication ->
just fyi
yeah yeah so disregarding raazor
oh yeah so in "pure" VSA, all things related to your feature goes in the same place
thats really all VSA is
the thing is, in reality thats not a lot of things... because a file might need to be associated with who uploaded it
or the user page might need to list all files uploaded by that user
etc
still, you can minimize the crossover but allow it where its needed
I guess what my semi beginner brain has trouble with is since ive so far only done EF Core MVC ive written controllers that return viewmodels to views. So im finding trouble figuring out how lets say vertical slice goes from talking and handling data to exposing the data to (in my case i guess razor pages)
you'd just have a bunch of controllers
one per feature at least
I see
possibly more
I recently wrote a small standalone statistics service for work that is somewhat VSA - I went with one controller for ingestion, one for querying and one for admin
interesting i think its getting a bit more clear
so since you said you feel like i dont need mediatr
per feature i can have a Interface for leats say ICreateProductService then an implementation, and in the handler/ in my case razor page i just call the service which is abstracted
/Products
/Create
Create.cshtml razor page
Create.cshtml.cs (razor pagemodel, calls ICreateProductService service)
CreateProductRequest.cs
ICreateProductService.cs
CreateProductService.cs
CreateProductValidator.cs
does this make sense as an example?
@Pobiega
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
I don't really like services in general, they are too broad for my liking
I'd rather model that as a
CreateProductCommand
and if you really need to inject that somewhere and want to be able to mock it for testing, then sure make an interface... but if you don't - no interface. Especially for web apis etc integration testing makes more sense, and then you dont need to do any mocking of internals anyways
its incredibly easy to create an interface if you change your mind, its even built into VS/VSC DevKit/Rider - just Extract interfaceThank you very insightful
Does it make more sense to have this razor page model kidn of coupled or does it make more sense to make controller for each feature and then make the razor page an http client so I can swap out front end in the future
again, no clue about razor - but generally its fine to couple things within the feature
Ty