Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I am trying to make the CommandTimeout value more configurable. I'm wondering if this is best practice to do so?

I add the following to my <appsettings> node in my Web.config file:

<add key="commandTimeValue" value ="60"/>

The I added the following to the top of my controllers under the :

using (var db = new myDAL())...

Int32 timeoutVal = Convert.ToInt32

(System.Web.Configuration.WebConfigurationManager.AppSettings["commandTimeValue"]);
((IObjectContextAdapter)db).ObjectContext.CommandTimeout = timeoutVal;

Is this the right way to do this? What are some other alternatives?

share|improve this question

1 Answer 1

I do not like the name myDAL as a class name. It is very cryptic and does not follow C# naming conventions. I would prefer DataAccessLayer or <entity>DataAccessLayer where <entity> is the name of the class the DAL is for.

That being said, why don't you inject the timeout value into your DAL class. The constructor could be something like

public void myDAL(int timeout)
{
    if (timeout > 0)
    {
         ((IObjectContextAdapter)this).ObjectContext.CommandTimeout = timeout;
    }

    // other constructor commands
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.