2
\$\begingroup\$

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?

\$\endgroup\$

1 Answer 1

5
\$\begingroup\$

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 } 
\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.