Programming, technology, and CRM – from a Belgian programmer exiled to Missouri
  • rss
  • Home
  • Soft Gallery
    • autosvnbackup.sh
    • VBScript Snippets
  • Contact Me
  • Welcome

Easy Business Rules with Extension Methods

Nicolas Galler | June 1, 2009

I just realized that I could use C# extension methods to avoid the whole “open architect, expand the little tree to find my entity, add the business rule definition, select the assembly, select the method from the assembly, save, copy comment from the C# project, save again, build, deploy, pray that the deployment actually worked” process.

I can declare my business rule like this:

public static void CalculateProcessTask(this ITicketActivity ticketActivity)

save as TicketRules.dll, and add this to the code to use it:

using TicketRules;

Another huge benefit is I can now use F12 to navigate to the definition. One less reason to open the Application Architect for – YAY! Sadly there is no way to do something like that for events, or for code snippet properties. But if you add the namespace used for the extension rules to the web.config/system.web/pages/namespaces element (see http://www.west-wind.com/WebLog/posts/2287.aspx for an example) you can use it in snippet actions.

It also opens the door to something that is a bit scary… it looks like those rules could be defined in App_Code (the folder that contains dynamically compiled code for ASP.NET). This would let us edit them without having to recompile… or restart the IIS app… mucho más rápido! But this prevents the code from being unit-tested, and makes it harder to manage, so I am not very likely to use it (business rules typically don’t need to be adjusted very often anyway, once they are unit-tested)

Categories
Uncategorized
Comments rss
Comments rss
Trackback
Trackback

« SlxGridHelper – Make the SlxDataGrid more convenient in our custom smart parts Things to try with Windows 7 / Win 2008 R2 »

Leave a Reply

Click here to cancel reply.

Categories

  • Experiments (4)
  • Interesting (1)
  • MSCRM (1)
  • Programming (60)
  • Rant (3)
  • Saleslogix (34)
  • Tricks (8)
  • Uncategorized (30)

Post History

  • 2010
    • January (3)
    • March (3)
    • April (2)
    • August (2)
  • 2009
    • March (2)
    • April (1)
    • May (3)
    • June (3)
    • July (1)
    • September (3)
    • October (2)
    • December (5)
  • 2008
    • January (9)
    • February (4)
    • March (9)
    • April (1)
    • May (5)
    • June (8)
    • July (1)
    • August (2)
    • September (1)
    • November (1)
    • December (3)
  • 2007
    • January (3)
    • February (7)
    • March (1)
    • April (3)
    • May (6)
    • June (2)
    • July (1)
    • August (2)
    • September (5)
    • October (3)
    • November (5)
    • December (4)
  • 2006
    • January (2)
    • September (1)
    • November (3)
    • December (4)
  • 2005
    • April (1)

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox