API Service Calls and Async ViewModel Loading - FULL STACK WPF (.NET CORE) MVVM #4

  Рет қаралды 25,506

SingletonSean

SingletonSean

4 жыл бұрын

I extend our service layer by creating a service to load information about major stock indexes. The service uses an HttpClient to retrieve JSON data from the FinancialModelingPrep API and uses Json.NET to deserialize the JSON into an object. Then, I use the service in a ViewModel to load major stock index information.
In this series, I walk through the development of a WPF application from the database layer to the UI layer.
API LINK: financialmodelingprep.com/dev...
SOURCE CODE: github.com/SingletonSean/Simp...
FULL PLAYLIST: • Full Stack WPF MVVM

Пікірлер: 54
@SingletonSean
@SingletonSean 3 жыл бұрын
The Financial Modeling Prep API now requires an API key. Learn how to set it up here: kzbin.info/www/bejne/hWeQXqKXh6iBeLs
@sebastianluft7441
@sebastianluft7441 3 жыл бұрын
It is limited to US only in free plan aswell now. I just faked my responses with Random() for now, don't wanna search for another API right now
@kadehoward2371
@kadehoward2371 3 жыл бұрын
I realize it is quite off topic but do anybody know of a good site to stream newly released tv shows online ?
@ms8367
@ms8367 4 жыл бұрын
This is so good!! Keep making WPF videos, please!! I'm learning so much!
@SingletonSean
@SingletonSean 4 жыл бұрын
Thanks MS204, more on the way of course!
@NatHollings
@NatHollings 3 жыл бұрын
Thanks for the videos man. 4 episodes in and learning a heap of new stuff!
@datka89
@datka89 3 жыл бұрын
You are a great man with awesome video tutorials. Thanks a lot!
@sivakumarr28
@sivakumarr28 4 жыл бұрын
Hey, you open my eyes to write a code in perfect way. I am looking forward to this guidance.
@sc100200090
@sc100200090 4 жыл бұрын
Man! Where had you been hiding? No doubt I had been searching for matchless and comprehensive videos like the same for quite some time, i.e. a WPF with SQL Server plus with an API on ".Net Core" clarifying the binding as well.
@vincentotieno9197
@vincentotieno9197 3 жыл бұрын
Hi SingletonSean. Thanks for the great work you are doing. I went through this episode today and it took me a while to figure out that I had to append my API key to the service Uri in order to get back data. Otherwise I'm learning a lot from this series. Please keep it up.
@SingletonSean
@SingletonSean 3 жыл бұрын
Thanks for the heads up Vincent. I added a pinned comment for my tutorial on how to setup the API key.
@2009baracuda
@2009baracuda 3 жыл бұрын
Thanks for the great course ! Since the API query syntax and results must have recently changed, in case someone wonders how to make tha service work, two things must be done. The model for MajorIndex must have the property 'Change' and not 'Changes' and in the service implementation the API (even for a single query) returns an Array. So we can just change the line with the Deserializer to : List majorIndexes = JsonConvert.DeserializeObject(jsonResponse); var majorIndex = majorIndexes[0]; Also the Uri with the new syntax could be built like this: string uri = $"financialmodelingprep.com/api/v3/quote/{GetUriSuffix(indexType)}?apikey=YOUR_API_KEY_GOES_HERE"; Hope it helps, have fun :)
@akshatube
@akshatube 3 жыл бұрын
Awesome man, this was very helpful, thanks a lot. :)
@unbekannt6111
@unbekannt6111 3 жыл бұрын
I changed the things but I still get an error. It seems that I get the response but cant extract the content of it correctly. So I always receive a empty array. Could u help me?
@imjdo
@imjdo 3 жыл бұрын
@@unbekannt6111 I had same problem, I fixed renaming MajorIndex properties with all lower case, sames a API results
@nbourre
@nbourre 2 жыл бұрын
You're the man!
@InfiniteFreeTrial1
@InfiniteFreeTrial1 Жыл бұрын
Awesome idea it worked, But the index of majorIndexes[0] always get data of the first Type into all other types !! , so How do I change it dynamically? I tried many ideas but nothing worked with me.
@huynhtruongduy8770
@huynhtruongduy8770 2 жыл бұрын
you are awesome, i have learned a lot from this series, thanks
@sirinebibicha2024
@sirinebibicha2024 Жыл бұрын
A very wonderful course,
@Freakhealer
@Freakhealer 3 жыл бұрын
Flawless. great series, I sub in first video I saw, not disappointed, really easy to follow. I started this series after a video I saw where you show how to change views thought it would be good to see the whole process of building the wpf app hope to learn how to reuse objects of Views instead of creating new Views always. at least for my project I wish to fill a textbox maybe go to other page and comeback still with the text on the textbox. Anyway have you noticed that you can pin your favourite type of projects in the new project page? could simplify your life ;)) big Thanks to you!
@rajeshbelliwali409
@rajeshbelliwali409 3 жыл бұрын
It's really helped lot..I am struglling because async was blocking thread...
@bieleckipawel1
@bieleckipawel1 3 жыл бұрын
When I create task within ContinueWith I get CA2008: Do not create tasks without passing a TaskScheduler. Adding TaskScheduler.Default fixes green squiggly but I'm not sure if this is correct way of dealing with the problem. What is your thougth on that? Many thanks.
@harvb5939
@harvb5939 Жыл бұрын
Sean, thanks for all the fantastic videos. I have learned a huge amount about WPF and other C# concepts. A question about the use of the static load method. Am I right in saying that the constructor is never called directly outside the class (I haven't yet watched the whole series)? In principle, could the constructor of the MajorIndexViewModel be set as private? I am asking to help my understanding. Apologies if you address this elsewhere. Keep up the excellent work.
@SingletonSean
@SingletonSean Жыл бұрын
Thanks Harv! That is correct, we could certainly make the constructor private. The only reason to keep it public would be if you wanted to instantiate the view model *without* also loading it, but we never do that in this app. Good question!
@davidporterrealestate
@davidporterrealestate 4 жыл бұрын
This is great, getting the data from a UI is good, but one thing I am struggling with is getting data from MediarR/Autofac, and having it stay in sync. If you could make a video on that that would be AWESOME!!
@SingletonSean
@SingletonSean 4 жыл бұрын
Hey David, thanks for watching! I've been reading into MediatR a lot recently, but I haven't decided if I want to use it yet. I understand the necessity for CQRS in some cases, but the one thing holding me back from MediatR is exception handling. I assume with MediatR, you really shouldn't throw any exceptions and should use Response objects. Let me know what you think. Keeping data in sync is difficult. You might want to consider implementing a layer between your UI and MediatR/service layer that manages application state. I kinda do this in part 14. To keep user data in sync throughout the application, I have a class in the state layer (I call it an Authenticator in the video) that will retrieve data and update the user state.
@idnafu
@idnafu 3 жыл бұрын
Hi @SingletonSean first i have to say big thanks your videos are great not only explaining things but also teaching best practices for Coding. I have a question regarding the LoadMajorIndexViewmodel. You call it inside the UpdateCurrentViewModel since i have no HomeviewModel as a container so i put it in the Constructor of the View where i assign the Datacontext Do you see anything wrong with that? public CharOverviewView() { InitializeComponent(); _viewModel = CharOverviewViewModel.LoadCharacterViewModel(); DataContext = _viewModel; }
@aelfar7533
@aelfar7533 3 жыл бұрын
This course is truly GOLD! I've recently started with C# .NET coming from a Java background and even if I'm still rough in my skills your teaching method is very clear to understand and follow. If you have a paid course on C# .NET i'll be glad to buy it so please link it in the comments if you do. I'm gonna be sending a bunch of people to see your videos :) THANKS!
@SingletonSean
@SingletonSean 3 жыл бұрын
That's wonderful to hear Ael Far! I have no paid courses as of now. I like the free content, helping as many people as possible, and growing this community :)
@FuzzyDPozzy
@FuzzyDPozzy 3 жыл бұрын
You know what would have been great if you could show how to go to documentation and use the api, I am struggling a lot with the documentation. Like the other day was reading github api couldn;t make anything worked.
@jirisykora4979
@jirisykora4979 3 жыл бұрын
Great video, thank you. But ... Doesn't Task.Result() block the UI thread?
@SingletonSean
@SingletonSean 3 жыл бұрын
Thanks Jiří! Task.Result does block the UI thread for uncompleted Tasks, but in this case the Task has already been completed since we're using Task.ContinueWith first. Regardless, I end up updating this in a future video because ContinueWith is kind of nasty.
@HugoM946
@HugoM946 Жыл бұрын
Hey Sean, great series, learning a lot of cool stuff here! Sadly it looks like the Financial Modeling Prep is enforcing premium endpoints for the API, Major Index being one of them, so it's no longer available to free users. Do you have any tips on how to follow the course without the financial api? Perhaps with some mock data simulating the calls...
@SingletonSean
@SingletonSean Жыл бұрын
Hi Hugo! I would recommend following this tutorial instead (it's much more concise and WPF focused): kzbin.info/aero/PLA8ZIAm2I03hS41Fy4vFpRw8AdYNBXmNm
@HugoM946
@HugoM946 Жыл бұрын
@@SingletonSean Nice, will do. I kinda jumped the gun and commented without checking your channel for the latest videos. That seems like exactly what I'm looking for. Thanks and keep up the good work! Cheers
@justinallen3037
@justinallen3037 Жыл бұрын
Hugo, It still works. Just sign up for a free account, use the same uri as in the video and add "?apikey=(key)" after the symbol/ticker.
@omerkorkut
@omerkorkut 3 жыл бұрын
json data ?
@ivandrofly
@ivandrofly 2 ай бұрын
16:33 - Another video on creating and returning viewmodel before entire init kzbin.info/www/bejne/bpiWZZueos58lbM (more detailed)
@jcturpin8737
@jcturpin8737 4 жыл бұрын
I was reviewing some of the code and remembered you asked if there was a 'better' way to write out the LoadMajorIndexes() function. I wouldn't say this way is better, but I tried adding in a ternary statement to make it more concise and it worked for me for both pass and fail scenarios: (seemed to work for me setting DowJones = null, or just putting null by itself at end of ternary) _majorIndexService.GetMajorIndex(MajorIndexType.DowJones).ContinueWith(task => task.Exception == null ? DowJones = task.Result : DowJones = null); //_majorIndexService.GetMajorIndex(MajorIndexType.DowJones).ContinueWith(task => //{ // if (task.Exception == null) // { // DowJones = task.Result; // } //});
@SingletonSean
@SingletonSean 4 жыл бұрын
Hey JC, that does look cleaner. You're really starting to sell me on these one-liners hahaha. I'm not sold on the property changed snippet you mentioned earlier yet, but this definitely looks cleaner. When I return to this view model (it needs some error handling), I'll definitely make this adjustment if I remember.
@jcturpin8737
@jcturpin8737 4 жыл бұрын
@@SingletonSean There's a fine line between concise and cryptic, and as the team I work with has always said, "The best format is the one who doesn't confuse the next programmer who comes along to maintain it." but it is nice to know of the options on a case-by-case scenario. Error handling might need more room than a one liner. :-) Thank you for your thoughts.
@jcturpin8737
@jcturpin8737 4 жыл бұрын
I found an interesting 'new to me' way to do a switch statement, called a switch expression. It's an alternative path to the same functionality and would look like this in the MajorIndexService.cs private string GetUriSuffix(MajorIndexType indexType) { return indexType switch { MajorIndexType.DowJones => ".DJI", MajorIndexType.Nasdaq => ".IXIC", MajorIndexType.SP500 => ".INX", _ => throw new Exception($"GetUriSuffix: Must use a valid index type. Type Used:{indexType}") }; } It also uses a 'Discard character' (the underscore), which I'm having fun figuring out how/when to use as well. :-) just thought I'd share, Thanks SingletonSean!
@SingletonSean
@SingletonSean 4 жыл бұрын
Hey JC, pretty interesting syntactic sugar! I can't tell if I like it or not, hahaha.
@jcturpin8737
@jcturpin8737 4 жыл бұрын
@@SingletonSean I thought it was a little odd at first, but I think I'm sold on it, though it would be on a 'case' by 'case' situation. ;-) I do like the use of lamda's over a keyword and colon. It doesn't look like it allows for 'fall through' though, but I never really do that anyway... Cheers! -Jeremy
Useful gadget for styling hair 🤩💖 #gadgets #hairstyle
00:20
FLIP FLOP Hacks
Рет қаралды 10 МЛН
小蚂蚁被感动了!火影忍者 #佐助 #家庭
00:54
火影忍者一家
Рет қаралды 32 МЛН
World’s Largest Jello Pool
01:00
Mark Rober
Рет қаралды 109 МЛН
КАК ДУМАЕТЕ КТО ВЫЙГРАЕТ😂
00:29
МЯТНАЯ ФАНТА
Рет қаралды 10 МЛН
Async Commands (and Async Relay Command) - EASY WPF (.NET CORE)
14:14
Pydantic Tutorial • Solving Python's Biggest Problem
11:07
pixegami
Рет қаралды 256 М.
The Logging Everyone Should Be Using in .NET
15:34
Nick Chapsas
Рет қаралды 51 М.
Writing async/await from scratch in C# with Stephen Toub
1:06:02
Turns out REST APIs weren't the answer (and that's OK!)
10:38
Dylan Beattie
Рет қаралды 128 М.
Dependency Injection in .NET Core (.NET 6)
1:00:32
IAmTimCorey
Рет қаралды 186 М.
Rate This Smartphone Cooler Set-up ⭐
0:10
Shakeuptech
Рет қаралды 6 МЛН
Что делать если в телефон попала вода?
0:17
Лена Тропоцел
Рет қаралды 3,4 МЛН