I'm very new to Autocad programming, few months new, but I managed to write an application with about 10 Autocad commands. Most of these commands show a window and everything else is done from that window. I try to make my application MVVM..ish. Because I have an almost 1 to 1 correspondence between Models ViewModels Views and commands I felt it would be appropriate to put the command inside one of the 3 parts of MVVM. First I decided to put the command in the ViewModel, then I realised that my command is only showing a window, and the ViewModel shouldn't handle windows, so I moved the command to the View's Codebehind. As I understood, it's ok to have code in the codebehind as long as it's strictly view related. Then I read about the CommandClass attribute on some tutorial provided by Autodesk and I found this:
CommandClassAttribute This custom attribute class is used to mark a type as the application's command class. An application may designate one, and only one, type as its command class. AutoCAD looks for an application's command methods on the type that bears this attribute.
This suggests that I should have one class to include all my commands. Then I read this, which confirms the above:
For an instance command method, the method's enclosing type is instantiated separately for each open document.
So my first approach to put commands in views or viewmodels was utterly wrong, because I would have viewmodel instances not doing anything else than running the command. Then I read this in ObjectARX's documentation:
If an application uses the CommandClass attribute, it must declare an instance of this attribute for every type that contains an AutoCAD command handler method.
Which bluntly contradicts the tutorial quoted above and also suggest that it's an approved practice to have more than one class to handle commands.
All Autocad .NET tutorials are projects with one class and one command, so you don't have to many choices about where to put what.
Could some experienced Autocad .NET developer provide a best practice, or at least an ok, or not wrong practice for managing Autocad commands in a rather large project?