Author Topic: IoC in AutoCAD  (Read 2553 times)

0 Members and 1 Guest are viewing this topic.

AngelKostadinov

  • Newt
  • Posts: 30
IoC in AutoCAD
« on: September 16, 2013, 02:41:43 AM »
Hi,
I would like to ask you, advanced programmers, is there some way to apply inversion of control when we are writing plugins for ACAD?
This idea comes from ASP.net MVC, where we substitute default controller factory with our factory and this enables us to create controller classes with constructor injection.
Does someone know how to do the same thing with AutoCAD?  Who calls our command class' constructor?

MickD

  • King Gator
  • Posts: 3637
  • (x-in)->[process]->(y-out) ... simples!
Re: IoC in AutoCAD
« Reply #1 on: September 16, 2013, 06:54:41 AM »
I'm not quite sure why you need a controller factory for AutoCAD commands.
In MVC patterns, particularly for web programming, the main controller (or router) routes the POST or GET request (or command if you like) to the right message handler but with AutoCAD you need to 'register' your commands on the command stack when you load your dll.
This means you need to define your commands explicitly using CommandMethod attributes or some other methods and when a command is typed in, AutoCAD searches the stack for the command callback to execute.

It sounds like you want to create your own command stack for your plug-in (that possibly overrides built in commands?) but I can't see the point, maybe I'm way off base here?? Can you elaborate a bit more?

Mick.
« Last Edit: September 16, 2013, 07:02:38 AM by MickD »
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: IoC in AutoCAD
« Reply #2 on: September 16, 2013, 07:15:27 AM »
@Mick
I imagine AngelKostadinov wants to do some unit testing where dependency inversion is used.

@AngelKostadinov
Do a search at AutoDesk University site for some lectures by Scott McFarlane

CP4471 Programming AutoCAD with C#: Best Practices

CP2654 Automated Testing with the AutoCAD® .NET API

Scott is currently writing new articles for Kean at Through the Interface and for this years AU ( I believe)


Hope this helps because it is a big subject.
Regards,
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

AngelKostadinov

  • Newt
  • Posts: 30
Re: IoC in AutoCAD
« Reply #3 on: September 16, 2013, 07:49:33 AM »
Kerry, you figured out my intentions with absolute precision!
Thank you! You give me an excellent starting point.
Regards,
Angel

MickD

  • King Gator
  • Posts: 3637
  • (x-in)->[process]->(y-out) ... simples!
Re: IoC in AutoCAD
« Reply #4 on: September 16, 2013, 06:13:17 PM »
Ah, thanks Kerry, that makes more sense now.

I still haven't got my head around unit testing yet, while those who use it swear by it, it is a lot of work....but that's another discussion :)

Best of luck AngelKostadinov.

Cheers,
Mick.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien