Resolved MVVM - persistent API key between viewmodels

ConsKa

Well-known member
Joined
Dec 11, 2020
Messages
140
Programming Experience
Beginner
I have an application that is hard coded with an API key....it works, perfectly fine.

I created a login screen so other people can use it with their API key.

It will not hold the API key, I have tried assigning it to a public property, I have tried creating a class to hold it in a property and then call to that class to get it, I created a textbox that was hidden and tried to write it to the hidden textbox....

I run the program, the first run through it works - the api key is there, it has been properly passed, but the moment it calls another method (the get method calls a datagrid view which is populated in another method by making selections form the json objects)....the API key is null and the json is null - hard coded - no problem. I don't understand why it goes to null, and I don't understand why the json goes to null - they are both properties which is how the different methods are able to populate the datagrid view without keep calling to the API.

I have seen solutions online, that require like 4 pages of code (exaggeration for effect) - and I just feel like....it can't be that hard can it? to simply pass a passkey to another viewmodel.

I am using Caliburn Micro for the MVVM model, dependency injection stuff - if that helps.

Thanks for any help offered, because this one has me stumped, I mentioned 3 things above - but I have tried like 15 stupid ideas that I am too embarrassed to post....
 
Caliburn.Micro follows suit with the same coding by convention.
I don't know anything about it Caliburn.Micro, and I never used it so I can't comment on it since I haven't a clue about the guts of it.
you said that you did Ruby on Rails for a while.
Yes when it was all about code, and now its all about gems. Libraries which are like Wordpress plugins. I got into it a few years after I got into c sharp. Ror was portrayed to me then as the future of web apps. Friend of mine was best friends with Hansson personally, which is how I got sucked into it. I left it, and went back to it a while ago and haven't gone near it since. I write in 21 other languages and Its impossible to write code for a different paradigm when you've been devoted to a different style of programming for a majority of those years. I have trouble writing bash after using c sharp. Not every dev has this issue, but admittedly I do.

So just because I done some thing previously, doesn't mean I should automatically identify a library apparently built using the same paradigm I once tried. Besides, c sharp doesn't use the same coding conventions, and if it did, wouldn't it be more focused on source and layout, instead of just source? All I know about Caliburn.Micro is that it aims to assist with both. I consider It to be the lazy mans pattern tool. Or maybe I just have the wrong understanding of it?
In which case, someone correct me.
 
Last edited:
All I know about Caliburn.Micro is that it aims to assist with both. I consider It to be the lazy mans pattern tool. Or maybe I just have the wrong understanding of it?
In which case, someone correct me.
I think lazy man's is a denigrating way of talking about libraries of this nature.

Does it make it easier yes, but is it lazy? Well no I don't think it is, I think it frees you up to write the applications that you need, without having to re-invent the wheel.

I am sure that reinventing the wheel would be educational, you would learn a lot, but it would also take awhile to do and would detract from the actual creation of things - maybe not for you, but for me that would take a considerable investment of time.

I am also moving on to learn python now as it is used in my new job - which I got off the back of teaching myself C# and building actual applications that people use on a daily basis and I was able to do that by utilising the tools that already exist that do the basic tasks, like Newtonsoft for example.
 
I feel like I am replying to topics poorly today... It's been a busy week, with very little time to write proper replies. @Skydiver The point I was trying to make on p1/#16 is that I can not write in certain languages for to long as it has a negative effect on the speed and the way that I write in those everyday languages that I mainly use, and this was one of the reasons why I don't use rails any more among a few others.

I like writing my own code. I don't like to use libraries unless I really have too. The likes of gems created by the rails community are libraries made by other people. This is also another reason why I don't use libraries, as I prefer to be the one in control of my own project and I must know exactly what my code is doing for the sake of performance and security. Since not all libraries come opensource, you can't always vouch for the security of a library you pick from Nuget and sources alike. I also prefer to write code my way, regardless of the good reputation a library author might have.

I am sure that reinventing the wheel would be educational, you would learn a lot, but it would also take awhile to do and would detract from the actual creation of things - maybe not for you, but for me that would take a considerable investment of time.
Not really, well not for me. I create templates of my projects that I use, with specific patterns already built into my templates. I keep multiple project templates with multiple patterns. This saves time, and requires very little effort to edit when creating a new project. Visual studio also lets you create project templates for convenience. Perhaps you should consider this next time you write an application Conska? Had you considered writing your own code and patterns from scratch, you likely wouldn't have hit a snag which you are now rewriting your application, regardless if its the fault of Caliburn.Micro or not. Patterns like the MVVM pattern are easy enough to write, but when you are not used to writing them yourself, it does sometimes take some trial and error and getting used too.

Also remember, as I pointed out above and I will quote :
That the observer pattern should only be used in complex situations where there are multiple models involved, and much to my amusement, the guy who developed it (John Gossman), also says its often overkill to use in simple applications according to the comments on that link I shared. As the developer of your application, you need to decide the pattern for your application, and that pattern will be and should be dictated by your applications requirements.
You don't need to use the mvvm observer pattern for every single project you do in WPF. Other patterns are also allowed in WPF. It's just that Microsoft brainwashed that particular pattern into our heads; including mine. As the other guys on here can tell you, that I was always a whiney bitch giving out about people not using the observer pattern. I myself have used it a lot in the past, but their are many other design patterns you can use too. I haven't seen John Gossman actually say what is said on the comments myself, but I have seen a number of other microsoft techs, say this, and today I kinda agree with people using other design patterns in WPF other than the observer pattern, providing they are supported by WPF itself. We don't always need to use the observer pattern for simple applications. As I have said before; your design architecture should be dictated by your applications requirement. Because if you look up what mvvm was designed to be used for, it was not intended to be used in every application, least of all - simple ones. The pattern was designed for use with complex bindings, and even multiple models. And that is something Gossman has said himself.

PS
I am also moving on to learn python now as it is used in my new job
I am really glad to hear this. That's a good move. I actually build all of my API's in Python now. I love Python, as it is very powerful, and always works without issues. It's a good move, as Python still has a great future! My only complaint I have with Python is that there is no dedicated control panel yet for web site hosting or some sort of web application to use for deployment.
 
Last edited:
Python has been interesting to learn - incredibly fast for the data science stuff. The thing that I miss, I won't say dislike but I do miss it, is the declarative variables - it is a string, I want it to be a string, let me tell you it is a string without casting it.

I also did take on board what you were saying, this particular application doesn't need models, it is simply placing a json in a datagrid based on a filter.

I have broken it so badly trying to fix the issue that arose that prompted this thread that I do need to rebuild it (though the logic is fine as far as I can tell) - and I will be doing it in a much simpler framework.

I am interested to see whether the same issue arises again.
 
But I would have thought you would have followed the documentation they appear to have listed on their site rather than a Youtube video...

I just wanted to respond to this part, because I thought this was kind of funny.

The video I referenced, from Tim Corey, isn't some bloke in his bedroom, he is a professional teacher, but what I thought was really funny was this:

He put out a video yesterday - says exactly what you were saying above - yes 3-tier applications are the 'standard' in the classroom, but you know what sometimes you just need a 1-tier application - it depends on what you need. Just thought you would find that interesting.

edit - not sure how this website feels about links to youtube - but if it is ok:
 
Sorry. Been a little crazy over here lately. I really wanted to reply back to this thread. The only reason why I made the comment regarding Calburn.Micro being like Ruby on Rails is with reference to the question regarding where was the DataContext being set. With most coding by convention frameworks, having to explicitly set or create things manually goes away because often it's boilerplate code, and so by using coding by convention, the boilerplate code doesn't need to be written, thereby freeing up the developer to focus their efforts elsewhere. The downside, is a lot of stuff seems to happen by magic unless the person reading the code is familiar with how the framework works.
 
He put out a video yesterday - says exactly what you were saying above - yes 3-tier applications are the 'standard' in the classroom, but you know what sometimes you just need a 1-tier application - it depends on what you need. Just thought you would find that interesting.
I don't actually. I have a major problem on other forums, not so much on here, but most places where I post, I get challenged quiet a bit on my coding ethics, opinions, but more-so when sharing how things will change later in some of the platforms. Yet, someone somewhere on different forums always manages to find something online to backup my claims. (Similar to the above).

I am very clued in, and keep myself well informed about what goes on in the industries I work in. It seems microsoft are moving away from using the MVVM approach. I've also said that microsoft would soon release a javascript only platform in place of asp.net or solely for use with asp.net. I guess time will tell how right or wrong I will be. They bought up their own js stack fairly recently. Wonder why?

The video I referenced, from Tim Corey, isn't some bloke in his bedroom, he is a professional teacher
:LOL::LOL::LOL:

A) He is only a 'youtuber'. He is also self-professed last time I checked him out. I don't even think he is a MVP. Some on the mod team here on this website are MVP's and I'd be bound to give them a lot more respect than Tim Corey.

B) He is promoted by the people at youtube, like all youtubers. And yes this is something I do know, as I have a lot of "famous" friends on youtube. I was given insider info on how the system works, while receiving private leads for people behind the system. Youtubers don't climb the ladder or manipulate their way to the top from using "keywords" or some of that shite you are led to believe. No, they are all selected by people in Youtube.

C) I also don't like him or his videos.

regarding Calburn.Micro being like Ruby on Rails is with reference to the question regarding where was the DataContext
I understood that from your previous reply, which is why I was talking about libraries and gems, but it seems you didn't read that, or you felt the need to explain it again.
because often it's boilerplate code, and so by using coding by convention, the boilerplate code doesn't need to be written, thereby freeing up the developer to focus their efforts elsewhere. The downside, is a lot of stuff seems to happen by magic unless the person reading the code is familiar with how the framework works.
Again, that is why I mentioned why I don't use libraries. For the same reason why most people haven't stuck with rails. I would be one of them. Rather than bringing my post forward again, go back and read what I said. I actually understood what you meant if I wasn't being clear before.
 
I felt like it went on a tangent when discussing libraries and gems when all I was trying to address was the missing setting of the DataContext. No need to repost, because like you, I prefer to see explicit code rather than have magic happen. If magic does happen, I'd like for there be a way to be to attach a debugger and trace through human readable source code to see how the magic happens. I think my only exception to magic frameworks are IoC containers and mocking frameworks -- as long as they get me the results I want, they can have all the magic they want to do.
 
We think very alike indeed.
I felt you were touching on what you wrote in p2/#21 when you posted this :
Unless specifically overridden, it will use convention to figure out which objects are related to each other and which should be injected where.
I just thought I'd expressly explain why I don't use rails for the same reasons you posted about directly above. If magic can happen in a library, then you are highly unlikely to find it easy to find your problem. Write your own code and save yourself the headache.
all I was trying to address was the missing setting of the DataContext.
Yea, but I'd never have known that, because i don't know anything about the library Conska was using. :)
 
I have a major problem on other forums, not so much on here, but most places where I post, I get challenged quiet a bit on my coding ethics

I think it's less that your opinions are controversial but the rather abrasive way in which you express them. I don't care, I have extraordinarily thick skin, I was also a barrister in the UK dealing with some of the worst criminals in the UK - so I am used to people behaving in ways that would be considered rude in the real world.

As to the rest of your post, 80% of it comes across as you patting yourself on the back and denigrating everyone else in the world simply because you know more. Did I claim Tim Corey was the best in the world? No, I just pointed out he wasn't a guy in his bedroom and was a professional teacher, which he is...but that can't be accepted by you, you have denigrate him and show your superiority in doing so.

If you don't want to be confronted so much, then really you should reign your neck in and stop putting everyone else down to feel better about yourself.

See that was harsh, but it was no harsher then everything you post.
 
Okay. That's enough gentlemen. Please both go back to your respective corners.
 
Back
Top Bottom