views:

37

answers:

2

User have to populate multistep questionnaire web-forms and step messages depend on the option chosen by user at the very beginning. Messages are stored in web.config file. I use asp.net mvc project, strong typed views and keep business logic separated from controller in static class. I don't want to make business logic dependency on web.config. Well, I have to insert message into view that depends on session value.

There are at least 2 options how to implement this:

  1. View model has property that is populated in controller/businessLogic and rendered in view like <%: Model.HelpMessage1 %>. I have to pass web.config values from controller to businessLogic that makes business logic methods signature too complex.

  2. Create static helper class that is called from view like <%: ViewHelper.HelpMessage1(Model.OptionChosenAtTheVeryBeginning) %>. But in this case logic what to show seems to be separated into two classes: business logic & viewHelper.

What will you suggest?

Thank you in advance!

+1  A: 

It appears that deciding which messages have to be displayed and / or how models are assembled from these messages is part of your business logic. How about storing the messages in your business layer and let your business layer generate the model with populated messages?

Adrian Grigore
I use WebSiteConfig static class for access to configuration values like: WebSiteConfig.Current.Message.Message1 ... is it ok to make dependency between BusinessLogic and such class? Or shall I refactor this somehow?
Andrew Florko
Web.config is not the right place to store such strings. You should use string resources for that: http://msdn.microsoft.com/en-us/library/3xhwfctz%28VS.80%29.aspx. I would create a resource files for all messages and put it in the business layer.
Adrian Grigore
Thank you for patience. Well, I use external file (web.config) in order to let experienced users to modify messages (there is no administrative part for the site). Do I undestand correctly that there is no ability to edit resources till web site project will be recompiled?
Andrew Florko
That is correct. However, you could put the resources in an XML file and access that from your business layer via Linq to XML. It's a really easy thing to implement.
Adrian Grigore
ok, I'll follow your advice
Andrew Florko
+2  A: 

As Adrian pointed out, your problem belongs in the business domain. Why not get the message, and put it into a view model along with your other data/models.

Bigfellahull
I use WebSiteConfig static class for access to configuration values like: WebSiteConfig.Current.Message.Message1 ... is it ok to make dependency between BusinessLogic and such class? Or shall I refactor this somehow?
Andrew Florko