big OOF
❔ QuestionController
Souns like a good idea! I have a endpoint for bith Store and item, lets say i have a webpage that allows the user to add a new store and the stores items. Would you use two seperate calls(POST store and POST Item) or would you create anew POST-endpint? In that case it would be only one endpoint instead of two but i would have to seperate the POST-body to be able to insert it to the Store and Item table in the DB 🙂
9 replies
❔ Retrieve API data in C#
I think i understand the concept, i just got it twisted! In the case of adding a singleton:
1. Add singleton to service
2. Pass singleton to class via DI
I think it was the case with singleton that got me confused because using DI doesn't look to different to declaring it like:
If you understand what i mean 🙂
But i understand the value of having it in the container instead of declaring it in the class.
Thanks!
20 replies
❔ Retrieve API data in C#
Thanks for all the responses! Indeed a great read @pip, but i do have one question regarding the article:
He adds services like this:
services.AddSingleton<GetAllProjectsQuery>();
services.AddHttpClient<GitHubClient>(x => { x.BaseAddress = new Uri(GitHubConstants.ApiBaseUrl); });
services.AddSingleton<GitHubClientFactory>();
services.AddSingleton<JsonSerializer>();
The only reason you declare the singletons like above is so that you can access it via DI and dont have to instantiate a new class? For example,
This: services.AddSingleton<GetAllProjectsQuery>();
Replaces: private readonly GetAllProjectsQuery _getAllProjectsQuery;
Am i understanding it correctly? 🙂
20 replies
✅ API result
Okey now i see the reasoning behind the DTO, thanks @Pobiega!
One additional question regarding EF:
This generates a field "GroupId" in the persons table
While this dosent
I want to use the latter i think (because a group can hold multiple persons) but how will i ever be able to query Person to include group if the Person object dosent hold a reference to the group object/class/table? 🙂 Or do a DTO solve this problem and im maybe a bit slow? 🙂
86 replies
✅ API result
@Pobiega Thank you, it worked when i changed from ICollection<Group> to just Group but when im using ICollection i get no data at all. I also tried to add a relation in the Group class:
Sadly i get a object cycle error, do i understand it incorrectly or do u just need to alter my LinQ select:
var a = await _context.Person.Include(x => x.Group).ToListAsync();
Thanks in advance 🙂
86 replies
❔ Architecture
@ChucklesTheBeard okey thanks! A follow-up question, i have a model class that I'm using when dezerializing retrieved JSON from an API. From what i understand you never write function into the model class? - It should only contain the model 🙂
6 replies
❔ Understanding inheritance
Okey, so in a way this solution is using two DI-containers? IserviceCollection and autofac or is autofac an extension of IserviceCollection?
Another question since im not that experienced with lambda expressions. If you were to transform the code below into words, can you say:
- When something is registred, is it of type IOrderQueries
-> return a OrderQueries object? 🙂
20 replies
❔ Understanding inheritance
Damn, my mind is blown! Ive had such a hard time grasping the whole DI-container term. Cant thank you enough!
Something that still is a bit vague to me is where the conditions or default class is set for the interface. I attached the Startup file and added a comment under CunfigureServices. Im thinking it would look something like this:
Im having a hard time to really understand everything in the startup file, maybe there is a conditions that ish-does what i mentioned above but that i just cant relly see it with my own eyes. Can you tell? Or maybe i misunderstood something? 🙂
20 replies
❔ Understanding inheritance
Ah okey, i think i just realised something! Whenever i add something to IServiceCollection services i can say that i added it to the DI-container, right?
For example:
.Service.AddMVC just adds the classes that are needed for MVC to the DI-container? -> and are therefore avaliable in whatever class we instantiate it in? 😄
20 replies
❔ Understanding inheritance
Thank you!
This is from the startup file, my guess is that the logic which class that is "selected"(for example as default) comes from one of these lines, am i correct? 🙂
.AddApplicationInsights(Configuration)
.AddCustomMvc()
.AddHealthChecks(Configuration)
.AddCustomDbContext(Configuration)
.AddCustomSwagger(Configuration)
.AddCustomIntegrations(Configuration)
.AddCustomConfiguration(Configuration)
.AddEventBus(Configuration)
.AddCustomAuthentication(Configuration);
As a example, if you were to change which class is given as default, you would have to look into one of the mentioned above? 🙂
20 replies