So far as I understand, SimpleIoc uses GetInstance method to retrieve an instance of a class that is registered. If the instance doesnt exist, it will create it. However, this instance is cached and always retrieved, which mimics the singleton pattern.
My thinking is that there is no need to keep an instance of ViewModel in a memory if there is a small possibility that this ViewModel will be needed twice, so I would like to create new instance of it each time that is needed. If we have are having a factory for ViewModels, we will have a property like this:
And another question is, in MVVM Deep dive session Laurent uses GetInstance method right after he registers a particular ViewModel, in order to, as he says, ensure that there is already an instance of this ViewModel in container. Why exactly is this necessary? If you are fetching a ViewModel through ViewModelLocator, then you will create it whenever required. So why would I want to have them created upfront?
You can get a different instance each time by passing a different key to the GetInstance method. However the instances will be cached, so if you do not want to keep them in the cache, you will need to call Unregister with the corresponding key.
In the demo, I was creating the VM upfront because the MainVM was sending messages to the SecondaryVM. Since the registration to the Messenger is done in the SecondaryVm's constructor, it needs to be created before it can start receiving messages. The Messenger is great because it is very decoupled, but it is one of these cases where you need to do extra work to compensate the decoupling: The SecondaryVM is the target of messages even though the MainVM does not get any reference to it.
After wrestling with SimpleIoC to provide new instances each time a specific type is requested and finding out this feature is not implemented (the key-based method accepted above doesn't fit scenarios where you want to say, perform a database operation and throw the connection away each time), I came up with a relatively decent solution combining IoC with the Factory pattern:Create a class that takes the responsibility of instantiating new instances of a certain type through a function:
However, remember you are not bound to use a secific container with MVVM. In several of my projects I used Unity, but every other IOC container will to equally well, it is a matter of requirements, customer preferences, and - if everything else fails - plain old personal gusto.
After reading all, very educational and high-quality answers in this thread I only would like to point something maybe not so advanced technologically but I think quite important to be placed in the thread about customizing IoC Container: I think that writing you own IoC Container is one of the easiest my-own-libraries-related task in OOP and I am pretty sure valuable educationally. I don't put any tutorials here because hopefully everybody that read my opinion knows Google Search or tools alike ;-)
I am a huge music enthusiats along with computers and use both, I was looking for a tagger program with some features like FLAC support, album art and of course batch tagging and I stumbled upon this program within 20 minutes I was pleased. I also wanted something that integrated with the Windows shell (right-click editting) and literally jumped for joy when I was playing around with Mp3tag
Input a URL to for an image - Now that we can paste album art, I would now love the abilty to input any direct image link (for example, www.mysite.com/albumartpic1.jpg) so that the program can quickly download the image, this great feature would suite nicely, this feature should too be able to: resize the image to gievn dimensions before writing as art to the file, also have a login and password filed in where if the site requires to login then user can input login and pass
see the screenshot I have taken of this program and editted to show you all what I mean
as you can see from the image that I enjoyed editting in MS Paint it would be nice, NOTE: the 'configure' button would do - login and password field, set image dimensions, rename image, internet-proxy settings. All images downloaded can download into a TEMP directory first or can download straight into the program whichever is best.
More advanced tags and the option to show them as default - Record Label, URL, composer, disc number, ripping tool, enocoder, language, rip date, copyright - I really am interested in the 'record label' tag that can sometimes go under the tag name of 'Publisher' or simply 'Label' if they are in the program I just can';t seem to find them
see this image (same image) -
SORTED - This program just keeps getting better and better, I found it its ok - File>Options>tag panel - I could add my own default entries, including 'record label' (which is under PUBLISHER) entries FANTATSIC this is what I have always wanted to do - tank you Florian
With that in mind, I like the suggestion of the shell popup. I use AudioShell, but it always seems to break when installing other audio based programs. Most times when I install the updates to Mp3tag, this occurs. That means I then have to re-install AudioShell.
I think it would be nice to have the shell popup as part of Mp3tag instead. If it were part of Mp3tag, I think it would be cool to have the ability to say which tags you want to display...perhaps a checkbox in the Tag Panel.
Normally, it takes a few people to agree with an idea for it to be even considered.
I think it would be nice to have the shell popup as part of Mp3tag instead. If it were part of Mp3tag, I think it would be cool to have the ability to say which tags you want to display...perhaps a checkbox in the Tag Panel.
Exactly, thats what I would like too, I have installed audioshell after mp3tag so there was no break, I only installed AudioShell for the shellpopup but I much prefer mp3tag's tagging and would like to see a an optional shell pop up.
And regarding my other suggestion about the album art URL I think that it may take some extra testing but I have seen this feature on imageshack.us, just thought it would be nice to see similar in this program - hope Mr. Florian could have a look and make a judgement
I still think it can happen but only as an option after install, I think it can still be an integral part of this program. What I propose isd that people can have the option top download the DLL file from this site and then in an 'tools'>'options' we can tick or untick to have it - but it would require that single extra downloaded dll to be in the installation folder (practical and very optional).
To further my point a little, I never installed my version of IrfanView (another fabulous multi-image viewer program), all I simply did was copy the contents of an already installed version 4.0 from my Laptop onto my other Desktop computer AND IT RAN FINE, eveen giving me the chance to add sheel extensions, see pic below, but you see it gave the user the option, just how mp3tag gave me the option to further the tag panel with more miscellaneous id3v2 - option giving simple
You can load and unload shell extensions without rebooting. After unloading a shell extension the dll isn't locked anymore and you can replace it. You can do that with many locked files, use "regsvr32.exe /u" on it and move/delete/rename/overwrite it.
On topic: Well, I like the idea of having such a shell extension. But I don't see the point why it has to be done by Florian. There are already shell extensions in existence that do that, no need to re-invent the wheel. Only thing I can think of that might be of interest is integrating Mp3Tag functionality into the Windows Explorer or generally havin this kind of shell extension as a "goodie" in the Mp3Tag package.
Are you sure about that? While I never coded shell extension myself, all shell extensions used by third party programs that I encountered were removed after a reboot or at least after manually killing all instances of explorer.exe. regsvr32 /u does unregister, but explorer.exe still keeps the file into memory.
Well, try it out yourself. I'm very sure that there are shell extensions that only require being unregistered to be "detached" from the Explorer and for the corresponding DLL file to be unlocked. Because I have compiled (not coded tho ) and used such extensions myself. When I can do it manually without a reboot, I don't see any reason why an installer cannot do it, too.
But still, you are quite right, there may be some cases were it is impossible remove extensions from the memory and thus unlock the files. Yet I don't know the exact reasons why this is the case. I solely speak from my own user experiences and I have seen both cases. Some program components definitely need a reboot or at least a re-login of the user so that they become totally visible... some extensions that deal with icons for example. It happened a lot of times that only after a reboot the correct icons for specific filetypes were shown after I have installed some software (e.g. graphic tool suites).
When you have the more than one explorer process enabled, then it may help to exit one of them, usually the one with the higher PID is the one that locks file type based shell extensions, so the famous "exit all program windows except this one (installer)" makes sense in this case. I have successfully deleted a DLL that was still locked after unregistering it. I had to close all Window Explorer processes (the root explorer.exe - i.e. windows shell - wasn't the one locking it). After unregistering the DLL all newly openend Window Explorer windows didn't load and lock the DLL anymore and I could delete it.
So my guess is that the above is only possible when you have "Launch folder windows in seperate process" enabled, but by default this is not the case, hence the main explorer.exe has to be restarted for some shell extensions to be removed... while this explains the reason why you have to restart after a uninstalling a program, it doesn't explain why you have to restart after an installation of some programs. My guess: probably for the icons to be refreshed or because some components are/can only be started during windows startup or user login.
7fc3f7cf58