Stores - WPF MVVM TUTORIAL #7

  Рет қаралды 24,178

SingletonSean

SingletonSean

Күн бұрын

Пікірлер
@msontrent9936
@msontrent9936 3 жыл бұрын
This is great. Really enjoying these series. All the way from SimpleTrader till now. I like how you organize your projects, your architecture, and all the visual studio coding shortcuts I learn along the way. Great work.
@SingletonSean
@SingletonSean 3 жыл бұрын
Great to hear, thanks MSon!
@feitan8745
@feitan8745 3 жыл бұрын
*Great as always*, i know this video is just about stores, but it does introduce other problems like poor concurrency management if not managed properly, for instance in a multi-user application where they interact with the same database, since it's fetch-once state (like here in the video) and the changes come from the application itself and doesn't propagate elsewhere you may find yourself making another another booking for the same person if you doesn't refresh or consult the existing bookings before making another one. This is just a note for those wondering or trying to use stores for such applications even if smaller, you should also manage those requirements separately (well defined functional requirements) aside from implementing the store. For most cases, even here it should just perform like a charm as long as it doesn't overlap your functional requirements. You're defitely have one of the best content about mvvm and wpf on youtube, following the conventions and good pratices, just hope more newcomers or junior developers could watch and learn from here, people are still sleeping on desktop development.
@SingletonSean
@SingletonSean 3 жыл бұрын
Great to hear Feitan! I agree with pretty much all of your points here. In a multi-user application, this would definitely deserve more attention. I'll be forced to cover these scenarios in a future tutorial where I build an app that connects to a REST API (hence there could be many client application instances). Thanks for supporting the channel and always leaving insightful comments like these!
@rahimotv2999
@rahimotv2999 8 ай бұрын
OMG every wpf keywords and concepts are in this serie , i cant handel all this informations hh btw thank u for this you are so good at mvvm structure , i will take only what i need since i have a limited time , have a greate day
@lenaweitz8905
@lenaweitz8905 2 жыл бұрын
Very nice video, thank you!
@Ibadez38
@Ibadez38 8 ай бұрын
I haven’t seen a video that presents your journey, your training. I’m just wondering where and how you learned all this. Was it in a school? By reading Microsoft’s documentation? By watching videos like yours? Or maybe at work from your colleagues? I’ve been programming for two years and for example, I had never heard of the store system and Lazy. I’m just wondering if self-learning can really help me code the same way as you. That’s why I would like to know your journey in a few words.
@TheTigerus
@TheTigerus Жыл бұрын
What if another user adds something to database while we have cached reservations? New data won't be available until we restart the application, right?
@dasfahrer8187
@dasfahrer8187 3 жыл бұрын
Pretty cool. How would this work with more complicated objects that have foreign key relationships and child collections?
@olepatheonlyone
@olepatheonlyone 2 жыл бұрын
Hello, help me clarify it a bit, is using "Store objects" in this way some kind of established practice? I used to think that this is some kind of Repository pattern implementation, but that doesn't quite look like how Repository pattern is implemented in some other guides and also seems to be in a different place in the class hierarchy in the program. Moreover, the name kinda makes this really difficult to google, so I'm not entirely sure whether there are any other real-life examples of using this
@SingletonSean
@SingletonSean 2 жыл бұрын
Good question Nente! It is an established practice in frontend web development, which inspired me to use this in WPF. In terms of relationships to a repository, the store uses a repository in order to get data for the UI. The store sits in between the UI and services/repositories, and is responsible for managing state for the application. I can imagine it is difficult to find relevant Google results for "stores" hahah. Here is some relevant documentation from the frontend web development world: ➖ Redux (React state management): redux.js.org/api/store ➖ Vuex (Vue state management): vuex.vuejs.org/guide/
@olepatheonlyone
@olepatheonlyone 2 жыл бұрын
@@SingletonSean Thanks for your reply. I haven't really worked with web development much, but I'll check these out, I guess. From what I understand, the 'stores' basically hold 'state' of the program? I'm not very familiar with the inner workings of web applications, but at least I think I can comprehend what the 'state' could be for a desktop application, on the example of this project. Just wondering: to me it felt like you're saying that as if this practice of using 'stores' is more suitable for web, i. e. you were just 'inspired' by it and sort of ported it into a desktop app. Then does it mean that there are other (probably more common) methods to do this which are more often used in the desktop apps instead?
@ivandrofly
@ivandrofly Жыл бұрын
@@SingletonSean Thanks for the links
@tarekjrd75
@tarekjrd75 3 жыл бұрын
Hey Sean, I'm enjoying these series very much. Can you give us an exemple On Update and Delete Reservation ?
@SingletonSean
@SingletonSean 3 жыл бұрын
Hey Tarek! I have a new series coming out for a new application that will tackle more CRUD and advanced operations. Stay tuned, and glad this is helpful!
@tarekjrd75
@tarekjrd75 3 жыл бұрын
Great. Keep it Up 👌
@freddycancino1
@freddycancino1 2 жыл бұрын
Hi, thanks shared , a question ; what happend with ID in table, i see in UI new reservation but cannot manipulate how to update after of add. Im sorry dont speak english
@geocine
@geocine 2 жыл бұрын
Hi Sean, what do you use for more control on states that can be solved by state machines. Want to pick your brain how would you structure it
@2024manohya
@2024manohya 11 ай бұрын
Tank you
@UserUser-sh6wi
@UserUser-sh6wi 2 жыл бұрын
What are good practices for deciding what should be in a store and what should be in a model? Lets say you have a single view application that has some settings. Like a password generator utility for example. You have settings for how long the password should be, what characters to use, etc. These settings dictate how the UI looks (textbox input, toggle switch state, dropdown content, etc) but are also used by the generator service. They make sense in a store but you could also argue that they belong in a settings model. Or perhaps a model in the store?
@feitan8745
@feitan8745 Жыл бұрын
It's been a while, but for the newcomers and more, you can narrow that way: entities -> features -> (you can go further if necessary). Since they're likely to be originated after you define services you just need to narrow to something more manageable.
@sir1usbl4ck333
@sir1usbl4ck333 3 жыл бұрын
Hi Sean! So far you showed plenty of how to add a new item with stores and handle everything with services. How about updating an existing item ? Passing an ItemViewModel to the store sounds "wrong" and editing the Item ( from the service) Wont update the lists, (without a remove + add )
@SingletonSean
@SingletonSean 3 жыл бұрын
Good question Filippo! I have a new, larger WPF tutorial coming soon where I implement this. The source code is available on GitHub. Basically, you could have an Update method on your store. The Update method would update the data in the store, and then raise an event to notify view models of the update: github.com/SingletonSean/youtube-viewers/blob/master/KZbinViewers.WPF/Stores/KZbinViewersStore.cs#L59 Then in your view model, you could subscribe to the update event on the store, and update the view model: github.com/SingletonSean/youtube-viewers/blob/master/KZbinViewers.WPF/ViewModels/KZbinViewersListingViewModel.cs#L86
@sir1usbl4ck333
@sir1usbl4ck333 3 жыл бұрын
@@SingletonSean Amazing as always :D Can't wait for this new tutorial
@furkanbekereci1077
@furkanbekereci1077 2 жыл бұрын
Hey Sean! This is the great tutorial series. Actually something confused me. Why don't we unsubscribe from the event inside of the deconstructor if we already need a leaving position? I mean you have a _hotelStore and deconstructor. Isn't it sure to make it correctly? Great work. Thanks.
@matthewpitts2770
@matthewpitts2770 3 жыл бұрын
Would it be bad practice to implement INotifyPropertyChanged in a store? Or I could invoke an event directly from the setter of a public property, or is this bad practice? I plan on using this on a public property in a store, which is getting/setting from the equivalent public property of the model.
@SingletonSean
@SingletonSean 3 жыл бұрын
Good question Matthew! I prefer only using INotifyPropertyChanged on view models to ensure that I or other developers on the project don't bind directly to the store. That said, I think INotifyPropertyChanged is okay on stores as long as the view isn't binding directly to the store.
@MsQlan
@MsQlan 3 жыл бұрын
Hey Sean, thanks again for your awesome tutorials. I have a question regarding placement of logic. I'll try to explain as best I can here. As with your example I have created a store (InventoryStore) to cache the results from the Inventory domain class that fetches all Inventory objects from a repository. Now I would like to implement both properties and methods with LINQ statements. For instance to get an IEnumerable of all the objects with a certain status. My first thought was to place these in the Inventory (domain) class but then the caching of the store would not be used. Two examples of required logic: public IEnumerable Warehouses => _inventoryAssets.GroupBy(x => x.Warehouse).Select(y => y.First()).Select(z => z.Warehouse); public async Task LoadOrderedAssets(int orderNumber) { ... } Thank you so much for any insight you may be able to provide.
@SingletonSean
@SingletonSean 3 жыл бұрын
Hey MsQlan! I agree that it would be ideal to organize this logic in the domain layer. I think I would need a bit more context to fully understand the issue. It might also be beneficial to introduce more stores. Based on your example, you could have a "WarehouseStore". However, I'm not sure if that addresses your concerns here.
@MsQlan
@MsQlan 3 жыл бұрын
@@SingletonSean Thank you for your prompt response. My apologies for my not explaining things properly. Maybe it would be simpler to apply the question to the Reservoom project. How would you go about creating a statistics screen next to the reservation listing? The screen would contain bookings this week and total amount of bookings. To avoid repeat requests to the database it would seem logical to use the cached list in the HotelStore. Maybe a ReservationStatisticsStore could be created that uses the HotelStore as its source of truth. But would we then place the LINQ statements in the ReservationStatisticsStore or a new ReservationStatistics domain object. And if so, how should the ReservationStatistics class get the cached list from the HotelStore?
@SingletonSean
@SingletonSean 3 жыл бұрын
I see what you mean now! I think we're on the same track here. I like the idea of having the HotelStore be the source of truth: 1. the ReservationStatisticsStore could listen to an event on the HotelStore, such as ReservationsLoaded 2. when that event is raised on the HotelStore, the ReservationStatisticsStore could update it's own collection of ReservationStatistics domain objects 3. the ReservationStatistics domain objects would hold the LINQ statements 4. the ReservationStatisticsStore could expose the results of those LINQ statements This would be fun to actually demo. I think one thing missing from this tutorial is having stores that depend on other stores, which is something I usually have to do in my own projects. Thanks for bringing this up, and let me know if you have any questions or need more info about anything!
@MsQlan
@MsQlan 3 жыл бұрын
@@SingletonSean Excellent explanation as always, I'll be looking forward to seeing a tutorial dedicated to this topic in the future. You did cover it a little in the SimpleTrader AccountStore which gave me the idea in the first place. One last question regarding the current setup with one store for the hotel. Lets say you need to open a specific reservation. Would you create a new GetReservation(RoomID roomID) method in the Hotell/ReservationBook classes or would you allow the HotelStore to query its cached list? Yet again it feels odd placing LINQ in the store to acchive this.
@hisoka1577
@hisoka1577 2 жыл бұрын
You are clearly very good at what you are doing and have so much to teach us beginners but please hear me out The way you edit your videos is as if you were making videos for the general public, that are used to the extremely sped up, meme format BECAUSE when I TRY TO FOLLOW your tutorials, they are just way too fast, sometimes there is a cut where I literally have to catch the last frame displayed so I can actually see what you did and in general this means I have to constantly pause the video to catch up with you and it makes the tutorial and the amount of information you put in just so overwhelming I would really like to follow your tutorials but the way you cut them up actually makes me have a really bad time doing that
@plixalcode
@plixalcode 2 жыл бұрын
Hi Hiso, I do agree that SingletonSean does go through the video quickly. It also seems that some frames have been cut out, but that is just my take on it. However, I run the video playback speed at 0.75 or sometimes at 0.5. Sometimes I speed it up to 1.75 if I am already familiar with the concepts and then set playback speed to 0.75 when I reach parts I am not familiar. He does sound very laid back when slowed down though 😀. I find changing play back speed very useful when coding along as well so I don't have to always stop the video, well sometimes I have to, but it works for me. Agree that it will make the tutorials a bit longer. Hope that helps.
@windowsbuilderthegreat3121
@windowsbuilderthegreat3121 3 жыл бұрын
Wouldn't it be better to make stores static
@emanueldoser7284
@emanueldoser7284 2 жыл бұрын
Hey Sean, first of all, I really like your tutorials, very well made and explained. Thank you! I had some questions related to the store approach but my original comment doesn't get posted (don't know why). Maybe it's in your spam? I would be very happy to receive a message if your limited time allows this :) Thanks in advance! Emanuel
@SingletonSean
@SingletonSean 2 жыл бұрын
Thanks Emanuel! I didn't receive your original comment with questions - you may need to re-send it
@emanueldoser7284
@emanueldoser7284 2 жыл бұрын
@@SingletonSean Hey Sean, thanks for the quick reply! I will try resend my comment, this is the original post: I was wondering if your limited time allows some thoughts on some issues I have related to the advantages and necessity of an in memory state like a store. I'm inexperienced in this area so I'm really unsure how to think about: 1. Lazy loading: Is it such a bad thing to query the db again and again? For example the recommended way of updating data in an ASP..NET (need two dots, this caused the problem of not posting the comment - a link which was not accessible...) app is to read the entity from the db before updating it (read first approach). It's to prevent overposting, but even than, would it be recommended, if it would be such a bad practice to requery from the db? (docs.microsoft.com/en-us/aspnet/core/data/ef-mvc/crud?view=aspnetcore-6.0#recommended-httppost-edit-code-read-and-update) 2. Sync/reactivity: To notify view models for model changes, we could also override the CUD methods of the DbContext and expose events there to which view models could subscribe (of course we must then use these methods). 3. Overall I feel a little bit like the store approach adds complexity we don't need necessarily (eg. database and store must be in sync, the store has no constraints like the db). Another question relates to updating entities. If we use update(), all properties/fields in the db get updated. Why don't attach the entity first and updating just those fields, which changed? I hope I was able to explain my issues well enough to be understood. Thanks in advance and thanks again for your great tutorials! Best regards Emanuel
@SingletonSean
@SingletonSean 2 жыл бұрын
These are good points Emanuel! In response to points 1 and 3, I suppose you could just continuously re-fetch from the data source if it is not a performance concern. This would ensure data is always in sync, but would require additional queries throughout the lifetime of the application. In response to point 2, this seems very similar to the store approach, just closer to the database. I could see this being a viable option for view model communication if done right. Overall, state management can be tricky, and there's not always a one size fits all solution. When handling state management in an app, it's certainly important to consider the questions that you raised!
@SingletonSean
@SingletonSean 2 жыл бұрын
Oh and another point about state management! It might not even be worth implementing until or unless your application is large enough to need or benefit from it.
@emanueldoser7284
@emanueldoser7284 2 жыл бұрын
Hi Sean, thanks for your answer! My app certainly needs something like state management. I need to do some more research to make a decision which approach fits best. The performance issue is a good point, I think some performance tests should leak potential problems. Currently I'm on vacation until the end of the week, than I will be able to do more research and rethink your points. I will let you know which decision I made or if I have a question :) Thank you! Emanuel
Feedback (Loading, Validation, Error Messages) - WPF MVVM TUTORIAL #8
19:49
The Basics of Data Binding in WPF
20:53
Tactic Devs
Рет қаралды 51 М.
번쩍번쩍 거리는 입
0:32
승비니 Seungbini
Рет қаралды 182 МЛН
Every team from the Bracket Buster! Who ya got? 😏
0:53
FailArmy Shorts
Рет қаралды 13 МЛН
УНО Реверс в Амонг Ас : игра на выбывание
0:19
Фани Хани
Рет қаралды 1,3 МЛН
What is the MVVM pattern, What benefits does MVVM have?
22:38
James Montemagno
Рет қаралды 105 М.
Is LEARNING WPF still WORTH it in 2023?
10:59
tutorialsEU
Рет қаралды 64 М.
ItemsControl (the "for loop" of XAML) - WPF TUTORIALS
10:04
SingletonSean
Рет қаралды 11 М.
AI Is Making You An Illiterate Programmer
27:22
ThePrimeTime
Рет қаралды 287 М.
OAuth 2.0 and OpenID Connect (in plain English)
1:02:17
OktaDev
Рет қаралды 1,8 МЛН
Loading Your React Data Like This is Awesome
13:27
Josh tried coding
Рет қаралды 116 М.
WPF Controls with MVVM: ItemsControl
33:34
IAmTimCorey
Рет қаралды 85 М.
Google I/O 2012 - Go Concurrency Patterns
51:27
Google for Developers
Рет қаралды 827 М.